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.
Installing cygwin might be overkill, but it gives you all the linux utilities.
I've used Tail For Windows. Certainly not as elegant as using
tailbut then, you're using Windows. ;)
I'd suggest installing something like GNU Utilities for Win32. It has most favourites, including tail.
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.
I've always used Baretail for tailing in Windows. It's free and pretty nice.
Edit: for a better description of Baretail see this question
Try Windows Services for UNIX. Provides shells, awk, sed, etc. as well as tail.
I use these and I don't have to cygwin my box. http://unxutils.sourceforge.net/
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.
There are quite a number of options, however all of them have flaws with more advanced features.
The Windows Server 2003 Tools provides a simple tail that can be downloaded with the Resource Kit Tools. It is too limited in many respects (locks followed file, lacks many options like --pid), however will do for the basic task of tracking a file.
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.
If you use PowerShell then this works:
Get-Content filenamehere -Wait
I prefer TailMe because of the possibility to watch several log files simultaneously in one window: http://www.dschensky.de/Software/Staff/tailme_en.htm
Anybody interested in a DOS tail using batch commands (see below) Its not prefect and lines sometime repeat.
usage: tail.bat -d tail.bat -f -f
@echo off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
rem tail.bat -d <lines> <file>
rem tail.bat -f <file>
rem ****** MAIN ******
IF "%1"=="-d" GOTO displayfile
IF "%1"=="-f" GOTO followfile
GOTO end
rem ************
rem Show Last n lines of file
rem ************
:displayfile
SET skiplines=%2
SET sourcefile=%3
rem *** Get the current line count of file ***
FOR /F "usebackq tokens=3,3 delims= " %%l IN (`find /c /v "" %sourcefile%`) DO (call SET find_lc=%%l)
rem *** Calculate the lines to skip
SET /A skiplines=%find_lc%-!skiplines!
rem *** Display to screen line needed
more +%skiplines% %sourcefile%
GOTO end
rem ************
rem Show Last n lines of file & follow output
rem ************
:followfile
SET skiplines=0
SET findend_lc=0
SET sourcefile=%2
:followloop
rem *** Get the current line count of file ***
FOR /F "usebackq tokens=3,3 delims= " %%l IN (`find /c /v "" %sourcefile%`) DO (call SET find_lc=%%l)
FOR /F "usebackq tokens=3,3 delims= " %%l IN (`find /c /v "" %sourcefile%`) DO (call SET findend_lc=%%l)
rem *** Calculate the lines to skip
SET /A skiplines=%findend_lc%-%find_lc%
SET /A skiplines=%find_lc%-%skiplines%
rem *** Display to screen line when file updated
more +%skiplines% %sourcefile%
goto followloop
:end
install MKS tool kit.. so that you can run all unix commands in windows.
tail -f is the command.