Tail command for Windows (CMD)

Tail is a Windows Server 2003 Resource Kit command, which is used from command prompt to print the last ‘N’ lines of a text file. This article covers the Resource Kit’s tail.exe, not a built-in Windows 11 or Windows 10 command.

Windows Resource Kit download

Tail was distributed with the Windows Server 2003 Resource Kit Tools. The original Microsoft download page is no longer available. The Windows Resource Kit download notes describe the old package and link to a separately hosted copy; this is not a current Microsoft download.
If you already have the tools installed, look for tail.exe in the installation directory, such as C:\Program Files\Windows Resource Kits\Tools. The examples below assume that directory is on PATH, or that you are running them from that directory.

Tail command usage

C:\Program Files\Windows Resource Kits\Tools>tail.exe -?
usage: TAIL [switches] [filename]*
switches: [-?] display this message
[-n] display last n lines of each file (default 10)
[-f filename] keep checking filename for new lines

Examples:

Advertisement

To print the last 10 lines of the file  data.txt:

tail -10 data.txt

If the file path contains spaces, put it in quotes:

tail -10 "C:\Logs\Application log.txt"

To print the data as and when it’s added to the file:

tail -f data.txt

The above command is mostly used for viewing log files contents while more data is being written to them. Tail command with -f option does not terminate until the user presses [Ctrl]-[C].

Advertisement

9 thoughts on “Tail command for Windows (CMD)”

  1. Tail gives ambiguous result.
    Sometimes right result and sometimes wrong result.

    See Below

    C:\afile>dir /b /od | tail -1
    cmd.txt
    
    C:\afile>dir /b /od | tail -1
    
    C:\afile>dir /b /od | tail -1
    
    C:\afile>dir /b /od | tail -1
    
    C:\afile>dir /b /od | tail -1
    cmd.txt
    
    C:\afile>dir /b /od | tail -1
    cmd.txt
    Reply
  2. When I call this tail -f toolkit command from perl on a windows 7 platform, the output is displayed in a command window and cannot, so far as I can tell, be captured in the perl program. Has anyone had success in capturing its output in the calling program?

    Thanks;

    Reply
  3. Thanks … note, that for Windows 7, install it with compatibility mode setting and it should install perfectly fine. It pops up a message saying there are known compatibility issues, ignore and proceed. Tried and tested and works absolutely fine on Win 7 (64 bit) Ultimate.

    Reply

Leave a Comment