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.
Join Stack Overflow to learn, share knowledge, and build your career.
closed as off topic by Ben Voigt, ChrisF♦, ЯegDwight, edorian, Jocelyn Oct 1 '12 at 23:03
Questions on Stack Overflow are expected to relate to programming within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.
-
Does this help? http://malektips.com/xp_dos_0001.html http://commandwindows.com/server2003tools.htm Here is the direct Microsoft link. I have tested it on my machine (just out of curiosity and because I might need it) and it works fine. – johnny May 8 '09 at 20:41
-
1Not exaclty a dupe but see here stackoverflow.com/questions/247234/… – Martin Beckett Aug 20 '09 at 16:59
-
mobaXTerm, it's free and has a log of plugins, you can do tail -f /drives/c/logs/mylog.log – surfealokesea Mar 2 '17 at 11:21
-
13 ways to tail a log file on Windows (stackify.com, February 2013) – joeytwiddle Mar 6 at 2:31
I'd suggest installing something like GNU Utilities for Win32. It has most favourites, including tail.
-
3I just tried to use GNU's
tailon a 2GB file and it choked.moreworked fine (at least viewing the start of the file). – Eric J. Mar 2 '12 at 0:13 -
@EricJ., same for me. On a 3GB file I can do
headbut nottail... Ideas? – Alphaaa Apr 23 '13 at 10:22 -
@Alphaaa: I suspect it has to do with the OS calls that GNU Utilities uses. See stackoverflow.com/a/4003487/141172 – Eric J. Apr 24 '13 at 0:27
-
@EricJ., thanks, that seems relevant indeed. But I just realized it's easier for me to use a workaround: I'm just going to write a simple script that does a
tail:) – Alphaaa Apr 24 '13 at 8:31 -
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
-
10
-
16This is good to know about; thanks. But I had a couple problems with it (on Windows 7). (1) it displays the entire file (not good for a massive log file, which is why
tailcan be useful) (2) it's not as dynamic as I'd like (maybe due to OS/filesystem changes between my setup and other posters?). That is, I determined that the shell doingGet-Contentsometimes doesn't update until I rundirin another shell. – mpontillo Mar 2 '11 at 23:33 -
8I think it's worth mentioning that PowerShell will pause scrolling / ouput if you select something inside the terminal window to give you a chance to read, copy / paste, etc. If you press Enter it will resume scrolling. – cbednarski May 19 '11 at 21:50
-
14PowerShell 3 introduces a -Tail parameter to include only the last x lines – Stefan Haberl Apr 4 '13 at 14:38
-
7So shouldn't the correct answer for Powershell be something like
Get-Content -Tail 100 -Wait .\logfile.log? – Henno Vermeulen Mar 1 '16 at 16:36
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
-
This ended up being the 1st solution that worked for me on [gulp] Windows Server 2003 R2 SP1! Super easy with installer, worked for tailing wasily right out of the box :) – cellepo Dec 5 '13 at 0:49
-
Downloading and executing unsigned executables over HTTP is probably not a good idea. At the very least, one should download through their HTTPS site. – Zero3 Sep 18 '17 at 13:57
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.
Anybody interested in a DOS CMD 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
-
This is clever, and I'm all about making use of existing functionality when downloading a tool isn't an option! This code will eat CPU though, as it will continually spin in followup for -f. – armstrhb Nov 14 '13 at 16:18
-
had the same problem with download and eating cpu! added this line
ping 127.0.0.1 -n 2 > nulbeforegoto followloop. it sends two pings and waits 1 in sec between. so it would let cpu live!:D – Mohsen ZareZardeyni Jul 4 '17 at 13:27
I've used Tail For Windows. Certainly not as elegant as using
tailbut then, you're using Windows. ;)
-
13I don't find your insinuation that the elegancy of a third party tool depends on the OS it runs on very helpful. Certainly having a grahical version of "tail" is no more or less elegant as the command line alternatives other answers are proposing. – Dave Van den Eynde Oct 9 '08 at 15:36
-
14Having a graphical version IS less elegant because there is overhead in opening the application, graphically selecting the file, and manually having to turn on monitoring. On the command line, it's just a few keystrokes. Is what I meant. Tangentially, no, I would not describe Windows as 'elegant'. – Jake Oct 9 '08 at 16:11
-
2There exists a graphical non-elegant program for windows that does this => windows is non-elegant. Great logic! Especially when both powershell and the resource kit which are provided by Microsoft support the elegant version of the functionality... – Cray Dec 6 '11 at 23:35
-
I second Tail for Windows. I like it because I can open and monitor multiple files in the same window. – Paul May 15 '13 at 15:26
I haven't seen Log Expert anywhere among answers here:
It's customizable and quite good for going around log files, so far it's the best windows graphical log viewer for me.
-
I love the features of Log Expert, however my experience has been buggy with it on Win 7 64 bit. – Clay Nov 14 '12 at 21:34
-
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.
-
11Windows is such a joy. I was into Unix when DOS first "came up" with subdirectories, and was abhorred to see them using \ for the path separator instead of / (as God intended). That was a portent to all the incompatible BS that came out of MS ever since. Does MS even have a grep? – xcramps Aug 20 '09 at 16:58
-
4Here is the batch of the previous explanation. It display the last 10 lines of the current file : ____ for /f "tokens=3" %%f in ('find /c /v "" %0') do set nbLines=%%f ____ set /a nbSkippedLines=%nbLines%-10 ____ for /f "skip=%nbSkippedLines% delims=" %%d in (%0) do echo %%d – Nicolas Jan 3 '11 at 16:23
-
1
Try Windows Services for UNIX. Provides shells, awk, sed, etc. as well as tail.
-
1
-
1Really? You're running around down-voting four year old answers? Way to contribute. – Dave Jun 29 '12 at 22:12
-
8@Dave: Even though the question is old, people are still looking at it trying to find the best answer. If an answer from even almost 5 years ago is not relevant or good anymore, then why shouldn't one downvote it? This whole site is about getting valuable information faster - today, not 5 years ago. – Oliver Jun 5 '13 at 16:35
-
1@Hellfire - you should be editing the answer with the proviso that it doesn't work with Wwindows 7. It's silly to just comment. – Preet Sangha Mar 5 '14 at 5:09
I've used Mtail recently and it seems to work well. This is the GUI type like baretail mentioned above.

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
DOS has no tail command; you can download a Windows binary for GNU tail and other GNU tools here.
Another option would be to install MSYS (which is more leightweight than Cygwin).
The tail command and many others are available in the Windows Resource Kit Tools package from http://www.microsoft.com/en-us/download/details.aspx?id=17657
-
I tried using this tail command, and for tail -n, it appears to actually print the last n+1 lines – ajs410 Aug 14 '12 at 23:02
I just wrote this little batch script. It isn't as sophisticated as the unix "tail" but hopefully someone can add on to it to improve it, like limiting the output to the last 10 lines of the file, etc. If you do improve this script, please send it to me at robbing ~[at]~ gmail.com.
@echo off
:: This is a batch script I wrote to mimic the 'tail' UNIX command.
:: It is far from perfect, but I am posting it in the hopes that it will
:: be improved by other people. This was designed to work on Windows 7.
:: I have not tested it on any other versions of Windows
if "%1" == "" goto noarg
if "%1" == "/?" goto help
if "%1" == "-?" goto help
if NOT EXIST %1 goto notfound
set taildelay=%2
if "%taildelay%"=="" set taildelay=1
:loop
cls
type %1
:: I use the CHOICE command to create a delay in batch.
CHOICE /C YN /D Y /N /T %taildelay%
goto loop
:: Error handlers
:noarg
echo No arguments given. Try /? for help.
goto die
:notfound
echo The file '%1' could not be found.
goto die
:: Help text
:help
echo TAIL filename [seconds]
:: I use the call more pipe as a way to insert blank lines since echo. doesnt
:: seem to work on Windows 7
call | more
echo Description:
echo This is a Windows version of the UNIX 'tail' command.
echo Written completely from scratch by Andrey G.
call | more
echo Parameters:
echo filename The name of the file to display
call | more
echo [seconds] The number of seconds to delay before reloading the
echo file and displaying it again. Default is set to 1
call | more
echo ú /? Displays this help message
call | more
echo NOTE:
echo To exit while TAIL is running, press CTRL+C.
call | more
echo Example:
echo TAIL foo 5
call | more
echo Will display the contents of the file 'foo',
echo refreshing every 5 seconds.
call | more
:: This is the end
:die
-
-
This just keeps reloading the text file. – user195488 Jan 31 '13 at 19:14
-
the batch version of echo has strange behaviour, if given no arguments it just exits, but if you call the command as
echo.with a trailing dot on the word(and not as a separate argument) it'll print a single new line. – scragar Sep 17 '14 at 12:35
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.
dos's type works like *nux's cat, though just like cat, it does dump the whole file, so its not really a true tail, but its going to be available in a pinch without downloading/installing a true tail substitute.
install MKS tool kit.. so that you can run all unix commands in windows.
tail -f is the command.
In Far Manager press F3 on a file to enter standard viewer, then End key to navigate to the end of file. If the file is updated - Far will scroll it automatically.
you can try WinTail as well http://www.baremetalsoft.com/wintail/
Graphical log viewers, while they might be very good for viewing log files, don't meet the need for a command line utility that can be incorporated into scripts (or batch files). Often such a simple and general-purpose command can be used as part of a specialized solution for a particular environment. Graphical methods don't lend themselves readily to such use.
I think I have found a utility that meets the need for the tail function in batch files. It's called "mtee", and it's free. I've incorporated it into a batch file I'm working on and it does the job very nicely. Just make sure to put the executable into a directory in the PATH statement, and away you go.
Here's the link: