A Windows equivalent of the Unix tail command [closed]
Asked Answered
P

26

511

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.

Psyche answered 9/10, 2008 at 14:48 Comment(11)
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.Lylalyle
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: microsoft.com/downloads/…Centipoise
Not exaclty a dupe but see here #247734Oneupmanship
mobaXTerm, it's free and has a log of plugins, you can do tail -f /drives/c/logs/mylog.logNematode
13 ways to tail a log file on Windows (stackify.com, February 2013)Trellis
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 topicAugustaaugustan
Voting to reopen; the question is on topic, but was closed only because there's no general consensus on the answer; SO's format is specifically designed to /find/ that consensus.Cnossus
asking about software is not a programming question. This question belongs to a different site. (SU probably)Pegg
Check out cygtail project on GitHub: github.com/JavaScriptDude/cygtailRosana
looks like a perfectly reasonable question to me ... in deed this is the first hit when i googled "windows tail log"Verditer
I recommend Klogg Works on massive files, GUI-based, open source, cross-platform (Windows, Linux, Mac), can tail file, can search fast, can scroll the 6GB+ files with ease.Irenics
P
151

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

Punitive answered 9/10, 2008 at 14:50 Comment(7)
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).Summitry
@EricJ., same for me. On a 3GB file I can do head but not tail... Ideas?Concurrence
@Alphaaa: I suspect it has to do with the OS calls that GNU Utilities uses. See https://mcmap.net/q/75158/-32-bit-windows-and-the-2gb-file-size-limit-c-with-fseek-and-ftellSummitry
@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 :)Concurrence
Does this work for Windows 7 too?Standstill
I tried it on windows 7 but i get zsh: command not found tailStilton
Here I believe is a better solution: #4426942Carburetor
L
632

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

Lynettalynette answered 9/10, 2008 at 16:42 Comment(21)
Actually this is not dynamicMorlee
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.Toffey
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.Chinua
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.Hg
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.Empery
Alternatively, you can use cat which is an alias for Get-Content, and is easier to remember for a linux guy!Bots
Does not work very well with a 1 GB logfile when I need just the last linesSomatist
PowerShell 3 introduces a -Tail parameter to include only the last x linesRainwater
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.Bonaventure
Get-Content myTestLog.log -wait | where { $_ -match “WARNING” } nicely filters the log using regexes too stackify.com/11-ways-to-tail-a-log-file-on-windows-unixAvalon
So shouldn't the correct answer for Powershell be something like Get-Content -Tail 100 -Wait .\logfile.log?Cretinism
Actually, you can use Select-Content in conjunction withGet-Content to output the last few lines: Get-Content c:\scripts\test.txt | Select-Object -last 5 https://mcmap.net/q/75157/-how-do-i-display-a-text-file-content-in-cmdGudrin
already established, but not good for 37gigabyte SQL dump file. going to use GSplit instead on it.Cavity
Just an example that works with the Tail option on the 100 last lines for Windows Server 2012 Get-Content filenamehere -Wait -Tail 100Plainlaid
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.Cherimoya
If needed, add parameter "-Encoding UTF8" or other encoding according to your file formatMattress
Seems like tail -f <file_name> is working in powershell (Win7)Sigil
so excited ^^ thanksArmbruster
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'Virescent
Thanks! It worked for me. To make it available to the "normal" command-promopt, I added it to a .bat file in path Powershell Get-Content %1% -Wait.Carbonous
@YogeshMahajan That is the best option, use a batch file that runs some PowerShell inside of it, sometime a full script embedded in the batch file! That is my goto tool these days. NOTE. You should consider calling Powershell with --noprofile optionPrelature
P
151

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

Punitive answered 9/10, 2008 at 14:50 Comment(7)
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).Summitry
@EricJ., same for me. On a 3GB file I can do head but not tail... Ideas?Concurrence
@Alphaaa: I suspect it has to do with the OS calls that GNU Utilities uses. See https://mcmap.net/q/75158/-32-bit-windows-and-the-2gb-file-size-limit-c-with-fseek-and-ftellSummitry
@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 :)Concurrence
Does this work for Windows 7 too?Standstill
I tried it on windows 7 but i get zsh: command not found tailStilton
Here I believe is a better solution: #4426942Carburetor
B
80

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

Bosson answered 9/10, 2008 at 14:52 Comment(4)
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 :)Wittgenstein
Downloading and executing unsigned executables over HTTP is probably not a good idea. At the very least, one should download through their HTTPS site.Cop
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.Mattress
amazing my friend, couldn't remember this name. :)Heribertoheringer
P
34

You can get tail as part of Cygwin.

Pat answered 9/10, 2008 at 14:49 Comment(0)
H
29

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
Hind answered 20/8, 2009 at 16:45 Comment(4)
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.Ilise
had the same problem with download and eating cpu! added this line ping 127.0.0.1 -n 2 > nul before goto followloop. it sends two pings and waits 1 in sec between. so it would let cpu live!:DArchfiend
Awesome! Thanks so muchLuwian
why employ ping if you could utilize timeout /t 2?Ichabod
H
26

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.

Helmholtz answered 9/10, 2008 at 16:10 Comment(1)
I've created a GitHub project with just the necessary binaries from Cygwin to get tail without installing. See github.com/JavaScriptDude/cygtail . Please try and comment in my repo if you have any issues.Rosana
P
22

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
Prelature answered 9/10, 2008 at 15:30 Comment(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 %%dLoaiasis
This is exactly what the poster wants, and it works just fine.Veiled
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.Hairsplitting
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.Prelature
The latest trick up my sleeve I do now, is that I write a batch file (.bat or .cmd) and inside of it I embed some PowerShell and I call it from there as such with powershell -NoProfile -Command "do something in powershell". This way, for the user it is still as simple as typing the batch command, but with the full-power of Poweshell behindPrelature
S
21

With Windows PowerShell you can use:

Get-Content <file> -Wait
Sosna answered 8/5, 2009 at 21:4 Comment(0)
W
19

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

tail
but then, you're using Windows. ;)
Witting answered 9/10, 2008 at 14:50 Comment(2)
I second Tail for Windows. I like it because I can open and monitor multiple files in the same window.Ambi
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.Isobelisocheim
D
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.

Divest answered 16/6, 2011 at 8:9 Comment(2)
I love the features of Log Expert, however my experience has been buggy with it on Win 7 64 bit.Noyes
I miss "clear view" functionality.Cadenza
L
11

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

Lineage answered 18/1, 2011 at 9:0 Comment(0)
E
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.

Emmott answered 9/10, 2008 at 14:54 Comment(4)
This has issues on Win7 and newer.Empery
Really? You're running around down-voting four year old answers? Way to contribute.Emmott
@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.Wilford
@Hellfire - you should be editing the answer with the proviso that it doesn't work with Wwindows 7. It's silly to just comment.Kin
V
5

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

Virgo answered 8/5, 2009 at 20:41 Comment(2)
Don't you find it strange how the link looks like it would be pointing to Microsoft, but it isn't? :)Shopkeeper
"There have been no native 64-bit resource kit tools produced and existing 32-bit resource kit tools are not supported on x64 platforms."Elbaelbart
O
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

Overture answered 22/4, 2009 at 11:27 Comment(0)
A
4

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

Afteryears answered 8/5, 2009 at 20:42 Comment(0)
Y
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.

Yaroslavl answered 8/5, 2009 at 20:45 Comment(0)
B
4

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

Briolette answered 8/5, 2009 at 20:51 Comment(0)
D
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
Dilantin answered 24/5, 2011 at 0:31 Comment(3)
nice idea using the "type" command, but you can't pipe to it!Schlesien
This just keeps reloading the text file.Spearmint
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.Sambo
A
4

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

Aleppo answered 24/5, 2012 at 2:19 Comment(3)
I tried using this tail command, and for tail -n, it appears to actually print the last n+1 linesElisha
"There have been no native 64-bit resource kit tools produced and existing 32-bit resource kit tools are not supported on x64 platforms."Elbaelbart
Confirmed, they don't work any more and are very hard to find regardless.Rosana
C
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.

Clipclop answered 9/10, 2008 at 14:51 Comment(0)
P
3

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

The command is:

tail -f <file-name>  
Pice answered 11/12, 2009 at 11:31 Comment(0)
J
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.

Jenness answered 15/7, 2011 at 5:55 Comment(0)
S
0

You can try WinTail as well.

ََ

Seleucia answered 11/8, 2010 at 8:19 Comment(0)
C
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.

Carmen answered 1/7, 2011 at 16:40 Comment(0)
C
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

Carmen answered 1/7, 2011 at 18:27 Comment(0)
E
-1

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

Externalism answered 13/2, 2011 at 12:7 Comment(1)
It's 70 € per install. That's not free.Horribly

© 2022 - 2024 — McMap. All rights reserved.