431

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Liam
  • 7,094
  • 3
  • 23
  • 26
  • 1
    Not exaclty a dupe but see here http://stackoverflow.com/questions/247234/do-you-know-a-similar-program-for-wc-unix-word-count-command-on-windows – Martin Beckett Aug 20 '09 at 16:59
  • Does this help? [http://malektips.com/xp_dos_0001.html](http://malektips.com/xp_dos_0001.html) [http://commandwindows.com/server2003tools.htm](http://commandwindows.com/server2003tools.htm) [Here is the direct Microsoft link.](http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en) I have tested it on my machine (just out of curiosity and because I might need it) and it works fine. – johnny May 08 '09 at 20:41
  • mobaXTerm, it's free and has a log of plugins, you can do tail -f /drives/c/logs/mylog.log – surfealokesea Mar 02 '17 at 11:21
  • [13 ways to tail a log file on Windows](https://stackify.com/13-ways-to-tail-a-log-file-on-windows-unix/) (stackify.com, February 2013) – joeytwiddle Mar 06 '18 at 02:31
  • 5
    I don't think this should have been closed, as I need this same thing to debug tracing in my windows application. It's about "software tools commonly used by programmers", which is on topic – kristianp Jul 04 '18 at 01:44
  • 1
    There actually *is* tail for XP, It's just that Microsoft doesn't install it with the standard version of XP; they packaged it in 'Windows Server 2003 Resource Kit Tools'. You can get it here: http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&DisplayLang=en – Matt Poush May 08 '09 at 20:45

26 Answers26

487

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

SliverNinja - MSFT
  • 29,007
  • 10
  • 98
  • 161
Alex
  • 11,537
  • 3
  • 29
  • 45
  • 13
    Actually this is not dynamic – Jey Geethan Mar 19 '10 at 08:35
  • 17
    This 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 `tail` can 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 doing `Get-Content` sometimes doesn't update until I run `dir` in another shell. – mpontillo Mar 02 '11 at 23:33
  • 11
    I 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
  • 1
    Man, for years I have wanted to do this on windows --- and finally searched -- StackOverflow came through for me -- this gives me a reason to have Powershell -- I never understood why we would want it. Thanks again for this post. Going into memory bank. – TravisWhidden Oct 14 '11 at 17:29
  • I have the same problem as Mike mentioned in his comment. It works, it is dynamic, but it seems to need a kick in the pants to get it to update. – Doug Wilson Jun 29 '12 at 16:29
  • 1
    Alternatively, you can use `cat` which is an alias for Get-Content, and is easier to remember for a linux guy! – CAMason Sep 24 '12 at 11:12
  • 4
    Does not work very well with a 1 GB logfile when I need just the last lines – Papuass Mar 05 '13 at 11:57
  • 21
    PowerShell 3 introduces a -Tail parameter to include only the last x lines – Stefan Haberl Apr 04 '13 at 14:38
  • Does not work in the case of a text file that has not flushed its output as a performance overhead. it thus ends up only generating output whenever the buffer gets full enough - which means it's never immediate and in my case often about 15 seconds late to update because it waits for 3 or 4 lines of output at least before it generates any output. – Conrad B Apr 27 '14 at 13:02
  • 3
    `Get-Content myTestLog.log -wait | where { $_ -match “WARNING” }` nicely filters the log using regexes too http://stackify.com/11-ways-to-tail-a-log-file-on-windows-unix/ – Matthew Lock May 07 '15 at 01:47
  • 8
    So shouldn't the correct answer for Powershell be something like `Get-Content -Tail 100 -Wait .\logfile.log`? – Henno Vermeulen Mar 01 '16 at 16:36
  • 1
    Actually, you can use `Select-Content` in conjunction with`Get-Content` to output the last few lines: `Get-Content c:\scripts\test.txt | Select-Object -last 5` [http://stackoverflow.com/a/37307879/325436](http://stackoverflow.com/a/37307879/3254362) – Michael Yaeger May 18 '16 at 18:53
  • already established, but not good for 37gigabyte SQL dump file. going to use GSplit instead on it. – JDPeckham Mar 10 '17 at 16:03
  • 1
    Just an example that works with the Tail option on the 100 last lines for Windows Server 2012 `Get-Content filenamehere -Wait -Tail 100` – sgirardin Mar 27 '17 at 09:54
  • I've just tried using `-Tail` and it's horribly buggy and tends to output way more lines that I ask for. I suspect the log file I'm reading has a mixture of line ending styles that PowerShell can't deal with, but I'm too lazy at the moment to confirm that. – kamilk Jul 07 '17 at 08:57
  • If needed, add parameter "-Encoding UTF8" or other encoding according to your file format – Lionet Chen May 28 '18 at 07:36
  • Seems like `tail -f ` is working in powershell (Win7) – zip_lock_throw Aug 24 '18 at 03:00
  • so excited ^^ thanks – thach.nv92 Nov 20 '19 at 09:57
  • This should be the correct answer. It works out-of-the-box on Windows. – 4thex Nov 21 '19 at 12:17
  • You can also use it the same as `tail -f | grep string` in *nix. `Get-Content -Path "file.txt" -tail 30 -wait | Select-String 'string'` – Gerhard Jul 16 '20 at 14:38
140

I'd suggest installing something like GNU Utilities for Win32. It has most favourites, including tail.

Community
  • 1
  • 1
Ryan Duffield
  • 16,649
  • 6
  • 36
  • 38
  • 5
    I just tried to use GNU's `tail` on a 2GB file and it choked. `more` worked fine (at least viewing the start of the file). – Eric J. Mar 02 '12 at 00:13
  • @EricJ., same for me. On a 3GB file I can do `head` but not `tail`... Ideas? – Alphaaa Apr 23 '13 at 10:22
  • @Alphaaa: I suspect it has to do with the OS calls that GNU Utilities uses. See http://stackoverflow.com/a/4003487/141172 – Eric J. Apr 24 '13 at 00: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 08:31
  • Does this work for Windows 7 too? – Madhusoodan Feb 08 '14 at 17:51
  • I tried it on windows 7 but i get `zsh: command not found tail` – Black Apr 19 '16 at 12:51
  • 1
    Here I believe is a better solution: http://stackoverflow.com/questions/4426442/unix-tail-equivalent-command-in-windows-powershell – Dung Jun 02 '16 at 15:34
67

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

Community
  • 1
  • 1
Instantsoup
  • 13,865
  • 5
  • 32
  • 41
  • 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 05 '13 at 00: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](https://www.baremetalsoft.com/baretail/). – Zero3 Sep 18 '17 at 13:57
  • 2
    I find it amazing that they keep maintaining the site and updating SSL certificate to date, while the software does not upgrade since 2006. It works fine though. Exactly what I needed. Windows Defender finds no threat. – Lionet Chen May 28 '18 at 07:29
  • amazing my friend, couldn't remember this name. :) – gds03 Mar 06 '21 at 14:01
32

You can get tail as part of Cygwin.

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205
25

Anybody interested in a DOS CMD tail using batch commands (see below).

It's 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
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
24

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.

Community
  • 1
  • 1
gz.
  • 6,363
  • 1
  • 19
  • 33
19

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

tail
but then, you're using Windows. ;)
Jake
  • 14,329
  • 20
  • 64
  • 85
  • 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
  • the powershell gc -tail way doesn't work if you're on a Posh 1 or Posh 2.x. The gc -tail functionality was added in Posh 3.0. – user1390375 Aug 07 '19 at 22:43
18

With Windows PowerShell you can use:

Get-Content <file> -Wait
OscarRyz
  • 184,433
  • 106
  • 369
  • 548
15

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
André Chalella
  • 12,511
  • 9
  • 48
  • 60
Philibert Perusse
  • 3,656
  • 5
  • 22
  • 25
  • 5
    Here 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 03 '11 at 16:23
  • 1
    This is exactly what the poster wants, and it works just fine. – Jackie Yeh Nov 10 '16 at 03:25
  • Thanks for the code! I added it to the answer with corrected parameter number and an extra one to the number of lines. Note it will display the lines an exit. PS: I used it to tail a 1.5Gb file and got the results in just 15 seconds. – Leopoldo Sanczyk Apr 09 '19 at 03:58
  • Actually, at step #4 it would even be better I think to use the command 'more' that takes a parameters as to the number of lines to skip. Even quicker I would think. – Philibert Perusse Apr 10 '19 at 13:05
15

I haven't seen Log Expert anywhere among answers here.

It's customizable and is quite good for going around log files. So far it's the best Windows graphical log viewer for me.

Unfortunately, this software is no longer available. You can read about it on archive.org.

Community
  • 1
  • 1
Grzegorz Gralak
  • 627
  • 8
  • 7
10

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

Vijay
  • 781
  • 2
  • 18
  • 32
5

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.

Kalana
  • 4,683
  • 6
  • 22
  • 46
Dave
  • 4,388
  • 2
  • 35
  • 57
  • 1
    This has issues on Win7 and newer. – Doug Wilson Jun 29 '12 at 16:49
  • 1
    Really? You're running around down-voting four year old answers? Way to contribute. – Dave Jun 29 '12 at 22:12
  • 9
    @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 05 '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 05 '14 at 05:09
5

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

ismail
  • 41,546
  • 8
  • 79
  • 92
  • 1
    Don't you find it strange how the link looks like it would be pointing to Microsoft, but it isn't? :) – Tomalak May 08 '09 at 21:12
  • *"[There have been no native 64-bit resource kit tools produced and existing 32-bit resource kit tools are not supported on x64 platforms.](https://en.wikipedia.org/wiki/Resource_Kit)"* – Peter Mortensen Sep 08 '18 at 21:18
4

The tail command and many others are available in the Windows Resource Kit Tools package.

amphetamachine
  • 23,162
  • 10
  • 51
  • 68
ucfjeff
  • 49
  • 1
  • 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
  • *"[There have been no native 64-bit resource kit tools produced and existing 32-bit resource kit tools are not supported on x64 platforms.](https://en.wikipedia.org/wiki/Resource_Kit)"* – Peter Mortensen Sep 08 '18 at 21:36
4

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
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Andrey
  • 41
  • 1
  • nice idea using the "type" command, but you can't pipe to it! – eadmaster Dec 14 '12 at 01:22
  • This just keeps reloading the text file. –  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
4

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

B.E.
  • 4,960
  • 4
  • 32
  • 41
4

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

Tomer Gabel
  • 3,976
  • 1
  • 30
  • 37
4

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Uberfuzzy
  • 7,863
  • 11
  • 39
  • 49
4

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

Dirk Vollmar
  • 161,833
  • 52
  • 243
  • 303
3

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.

Grant Wagner
  • 23,293
  • 6
  • 50
  • 60
3

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

The command is:

tail -f <file-name>  
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
3

In Far Manager, press F3 on a file to enter the standard viewer, then the End key to navigate to the end of file.

If the file is updated, Far Manager will scroll it automatically.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
anatoly techtonik
  • 17,421
  • 8
  • 111
  • 131
1

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

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
0

You can try WinTail as well.

ََ

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
GJ.
  • 4,270
  • 1
  • 17
  • 23
0

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.

0

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:

mtee

Kalana
  • 4,683
  • 6
  • 22
  • 46