HPS WinTail v.1.5 HPS WinTail is the ultimate Windows port of the Unix tail utility. Just like the Unix tail, HPS WinTail continually displays new lines as they are appended to a text file - for example, a log file or a trace output file.
18 Jan 2004
Introduction
This simple program imitates the unix 'tail -f' utility on windows.
Source code and Demo
The submitted source code contains one main file: Tail.cs. This is the core of the tail program. This file is used in two wrappers - a GUI wrapper and a CUI wrapper. The two projects in the solution illustrate using Tail.cs in a windows form application and a console application.
Code Walkthrough
.NET introduced the
FileSystemWatcher
, which is the main component of this program. By configuring this component one can listen to file system changes.I first check whether the file exists. If it does exist then I monitor any changes to the file thus:
If it does not exist yet, then I wait until the file is created before watching for file change notifications:
When a change is made to the file, the method below gets the notification
Within this, I ensure that the last characters are read in a large file which is longer than the number of characters that can be read. I then read the last set of characters starting from where we left off the previous time. The string of new characters is then sent to all listeners.
The sample programs listen to this notfication and then updates its user interface.
Issues
I have noticed an occasional exception saying that the target file is being accessed by another program. In the environment that I am working in, the target file is not always opened for writing, so I am able to get away with the above code for now. If it works, don't touch it uh. :-) But you feel free to correct it and post changes.
Bug Fixes
- Added fix for file access exception. Thanks to Gary a.k.a garythom_work for this fix. (see thread below) - 17 Jan 2004
Active2 months ago
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 Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
LiamLiam4,51933 gold badges2222 silver badges2626 bronze badges
closed as off topic by Ben Voigt, ChrisF♦, ЯegDwight, edorian, JocelynOct 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.
26 Answers
I'd suggest installing something like GNU Utilities for Win32. It has most favourites, including tail.
Community♦
Ryan DuffieldRyan Duffield14.4k55 gold badges3535 silver badges3838 bronze badges
If you use PowerShell then this works:
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 - MSFT25.3k99 gold badges8686 silver badges143143 bronze badges
AlexAlex10.3k33 gold badges2727 silver badges4545 bronze badges
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♦
InstantsoupInstantsoup12.4k55 gold badges3131 silver badges4141 bronze badges
QuentinQuentin691k8282 gold badges940940 silver badges10931093 bronze badges
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
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
formatguy
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.
5,62911 gold badge1717 silver badges2929 bronze badges
I've used Tail For Windows. Certainly not as elegant as using but then, you're using Windows. ;)
JakeJake7,0491919 gold badges6262 silver badges8383 bronze badges
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.
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
Grzegorz GralakGrzegorz Gralak
OscarRyzOscarRyz148k9999 gold badges350350 silver badges525525 bronze badges
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:
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.
André Chalella8,74188 gold badges4343 silver badges5757 bronze badges
Philibert PerussePhilibert Perusse2,58355 gold badges2121 silver badges2424 bronze badges
I've used Mtail recently and it seems to work well. This is the GUI type like baretail mentioned above.
VijayVijay56322 gold badges1313 silver badges3030 bronze badges
Try Windows Services for UNIX. Provides shells, awk, sed, etc. as well as tail.
DaveDave3,88122 gold badges3333 silver badges5555 bronze badges
Download the tail command, part of
ismailismailWindows Server 2003 Resource Kit Tools
from Microsoft itself.36.7k88 gold badges7373 silver badges8888 bronze badges
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.B.E.Wintail Download Windows 10
3,97044 gold badges2828 silver badges4040 bronze badges
DOS has no tail command; you can download a Windows binary for GNU tail and other GNU tools here.
Tomer GabelTomer Gabel3,50111 gold badge2828 silver badges3737 bronze badges
Another option would be to install MSYS (which is more leightweight than Cygwin).
Dirk VollmarDirk Vollmar145k4949 gold badges234234 silver badges292292 bronze badges
DOS's
Peter Mortensentype
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.14.5k1919 gold badges8989 silver badges118118 bronze badges
UberfuzzyUberfuzzy4,2541111 gold badges3535 silver badges4747 bronze badges
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.
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
AndreyAndrey
The
Peter Mortensentail
command and many others are available in the Windows Resource Kit Tools package. 14.5k1919 gold badges8989 silver badges118118 bronze badges
ucfjeffucfjeff
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 WagnerGrant Wagner20.8k66 gold badges4949 silver badges6060 bronze badges
Install MKS Toolkit... So that you can run all Unix commands on Windows.
The command is:
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
user229580
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 MortensenWintail For Windows 10
14.5k1919 gold badges8989 silver badges118118 bronze badges
anatoly techtonikanatoly techtonik13.2k66 gold badges9292 silver badges107107 bronze badges
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
user615011
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.
user825233
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:
user825233
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
GJ.GJ.Mcafee For Windows 10
3,77211 gold badge1515 silver badges2323 bronze badges