I have to look at the last few lines of a large file (typical size is 500MB-2GB). I am looking for a equivalent of Unix command tail
for Windows Powershell. A few alternatives available on are,
http://tailforwin32.sourceforge.net/
and
Get-Content [filename] | Select-Object -Last 10
For me, it is not allowed to use the first alternative, and the second alternative is slow. Does anyone know of an efficient implementation of tail for PowerShell.
Use the
-wait
parameter with Get-Content, which displays lines as they are added to the file. This feature was present in PowerShell v1, but for some reason not documented well in v2.Here is an example
Once you run this, update and save the file and you will see the changes on the console.
PowerShell Community Extensions (PSCX) provides the
Get-FileTail
cmdlet. It looks like a suitable solution for the task. Note: I did not try it with extremely large files but the description says it efficiently tails the contents and it is designed for large log files.try
Windows Server 2003 Resource Kit Tools
it contains a
tail.exe
which can be run on Windows system.https://www.microsoft.com/en-us/download/details.aspx?id=17657
For completeness I'll mention that Powershell 3.0 now has a -Tail flag on Get-Content
gets the last 10 lines of the file
gets the last 10 lines of the file and waits for more
Just some additions to previous answers. There are aliases defined for Get-Content, for example if you are used to UNIX you might like
cat
, and there are alsotype
andgc
. So instead ofyou can write
As of PowerShell version 3.0, the Get-Content cmdlet has a -Tail parameter that should help. See the technet library online help for Get-Content.