A Windows equivalent of the Unix tail command

Viewed 587437

I'm looking for the equivalent of the Unix 'tail' command that will allow me to watch the output of a log file while it is being written to.

26 Answers

If you use PowerShell then this works:

Get-Content filenamehere -Wait -Tail 30

Posting Stefan's comment from below, so people don't miss it

PowerShell 3 introduces a -Tail parameter to include only the last x lines

I've always used Baretail for tailing in Windows. It's free and pretty nice.

There are quite a number of options, however all of them have flaws with more advanced features.

  • GnuWin32 tail is buggy (α β γ) - things like -f just plain don't work.

  • UnxUtils tail seems better (-f works, but --pid seems not to, -n but not --lines=n fails with -f), but appears to be a dead project.

  • Cygwin is a big ugly mush, could perhaps just use the DLL and coreutils package - but still has problems like --pid not working with native win32 processes.

I've used Tail For Windows. Certainly not as elegant as using

tail
but then, you're using Windows. ;)

If you do not want to install anything at all you can "build your own" batch file that does the job from standard Windows commands. Here are some pointers as to how to do it.

1) Using find /c /v "" yourinput.file, get the number of lines in your input file. The output is something like:

---------- T.TXT: 15

2) Using for /f, parse this output to get the number 15.

3) Using set /a, calculate the number of head lines that needs to be skipped

4) Using for /f "skip=n" skip the head lines and echo/process the tail lines.

If I find the time, I will build such a batch file and post it back here.

EDIT: tail.bat

REM tail.bat
REM
REM Usage: tail.bat <file> <number-of-lines> 
REM
REM Examples: tail.bat myfile.txt 10
REM           tail.bat "C:\My File\With\Spaces.txt" 10

@ECHO OFF
for /f "tokens=2-3 delims=:" %%f in ('find /c /v "" %1') do (
    for %%F in (%%f %%g) do set nbLines=%%F )
set /a nbSkippedLines=%nbLines%-%2
for /f "usebackq skip=%nbSkippedLines% delims=" %%d in (%1) do echo %%d

With Windows PowerShell you can use:

Get-Content <file> -Wait

I've used Mtail recently and it seems to work well. This is the GUI type like baretail mentioned above. enter image description here

Try Windows Services for UNIX. Provides shells, awk, sed, etc. as well as tail.

Update -: Unfortunately, as of 2019 this system is no longer available on the Microsoft Download Center.

Download the tail command, part of Windows Server 2003 Resource Kit Tools from Microsoft itself.

DOS has no tail command; you can download a Windows binary for GNU tail and other GNU tools here.

DOS's type works like *nux's cat, though just like cat, it does dump the whole file, so it's not really a true tail, but it's going to be available in a pinch without downloading/installing a true tail substitute.

Another option would be to install MSYS (which is more leightweight than Cygwin).

If you want to use Win32 ports of some Unix utilities (rather than installing Cygwin), I recommend GNU utilities for Win32.

Lighter weight than Cygwin and more portable.

Install MKS Toolkit... So that you can run all Unix commands on Windows.

The command is:

tail -f <file-name>  

I'm using Kiwi Log Viewer. It's free.

Related