Wednesday, March 28, 2012

Replacement for Unix tail command in Windows

Wow - surprised to find that there is no direct tail command in powershell.  In the unix environment you can tail a logfile, very helpful tool.

In powershell you can look at the last lines of a file by piping content to select so ...
get-content <file> | select-object -last 5

UPDATE - powershell 3.0 now includes a last switch for get-content
get-content <file> -last 5
To watch a log file ...
get-content <file> -wait
but not exactly the same functionality.  So a better way is to get the command from Microsoft.

Tail is included in the 2003 Resource Kit and works well in Server 2008 environment.
Download tail here:
http://www.microsoft.com/download/en/details.aspx?id=17657