Unix tail equivalent command in Windows Powershell

mutelogan picture mutelogan · Dec 13, 2010 · Viewed 332.8k times · Source

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.

Answer

ravikanth picture ravikanth · Dec 13, 2010

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

Get-Content -Path "C:\scripts\test.txt" -Wait

Once you run this, update and save the file and you will see the changes on the console.