Early in my career, I did a lot of work on the UNIX operating system. Several years later, I found myself working strictly on the Microsoft stack – Windows Server, Windows XP / 7, etc. For many reasons, the Windows platform is far superior (I may be biased). However, every once and a while, I find myself looking for an easy ‘right-click’ way to do something that I used to do in Linux that I can’t do in Windows.
As a developer, one of my favorite commands was the ‘tail’ command. The ‘tail’ command would allow you to print the last lines of a file to the console, printing any new lines to the console in real-time as they were added. This functionality was perfect for observing log files for complicated ‘windowless’ applications during runtime, and I found myself really missing it on the Windows platform.
GNU Utilities for Win32
After a little searching, I stumbled across GNU Utilities for Win32 (http://unxutils.sourceforge.net/). The download is a zip file, which basically consists of several executable command line utilities that mimic UNIX / Linux commands. All included utilities interface directly with the Microsoft C-runtime (msvcrt.dll) making them more or less native to Win32. Once you have unpacked the zip file to a directory on your computer, you can update your environment path variable to point to this directory so that the utilities can be invoked from anywhere on your computer.
If I choose to tail a log file, such as the ‘app.log’ file, all I have to do is open a command prompt and invoke the ‘tail’ command.
Notice how the command prints the last 10 lines of the file and waits for the file to be appended to. As the file is appended to, the ‘tail’ command will append the new lines to the console. The ‘-f’ switch tells the utility to follow the file. Without it, the ‘tail’ command will simply print the last few lines of the file and exit. To see what else the ‘tail’ command is capable of, type ‘tail –help’.
Adding Tail to the Context Menu
I did miss the UNIX ‘tail’ command, and I did go looking for a utility that would allow me to do the same thing in Windows; however, did I mention that Windows is far superior? Why would I want to open a command line, navigate to the directory where my log file is located, and have to type the command when it would be so convenient to simply right-click?
Adding the ‘tail’ command to the Windows Explorer context menu was actually easier than I expected. In fact, adding your own personal context menu command is as simple as adding a single registry key.
Use the registry patch below to add the ‘tail’ command to your Windows Explorer context menu
Copy the following to a text file and name it ‘tail.reg’
Double-click on the file to add the information to your system registry
Windows Registry Editor Version 5.00
@=”\”C:\\Program Files (x86)\\Unx\\tail.exe\” \”%1\” -f -n 150″
If you examine the value of the command key, you’ll notice that it invokes the ‘tail’ command on the selected file represented by the ‘%1’ token. The ‘-f’ switch indicates that the tail utility should follow the file and the ‘-n’ switch indicates that the last 150 lines should be printed to the console before following. Make sure you update the path to point to the location of the tail.exe file on your computer.
Once the registry values are added, you should be able to right-click on a log file in Windows Explorer to invoke the tail utility.
If you have any questions regarding this blog, please contact us. For additional information about the services Credera offers in its Technology Solutions group, visit www.credera.com.