Rahul Sharma (Editor)

Tail (Unix)

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

tail is a program on Unix and Unix-like systems used to display the tail end of a text file or piped data.

Contents

Syntax

The command-syntax is:

By default, tail will output the last 10 lines of its input to the standard output. With command line options, the amount of output and the units (lines, blocks or bytes) may be changed.

In the following example only the last line of the reports is output:

This example outputs the last 4 characters of the reports, silently suppressing the filenames. Notice that the count includes the newline character at the end of each line and so the output does not include a leading space one might expect.

This example shows all lines of report from the second line onwards:

tail -n +2 report

Using an older syntax (still used in older version of Sun Solaris as the -n option is not supported), the last 20 lines and the last 50 bytes of filename can be shown with the following command:

tail -20 filename tail -50c filename

However this syntax is now obsolete and does not conform with the POSIX 1003.1-2001 standard. Even if still supported in current versions, when used with other options (like -f, see below), these switches could not work at all.

As with all unix commands, use man pages on the running system for specific options and actions.

File monitoring

tail has two special command line option -f and -F (follow) that allows a file to be monitored. Instead of just displaying the last few lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the file by another process, tail updates the display. This is particularly useful for monitoring log files. Ancient versions of tail poll the file every second by default but tail from the GNU coreutils as of version 7.5 support the inotify infrastructure introduced in Linux kernel version 2.6.13 on August 2005 which only check the file when is notified of changes by the kernel.

The following command will display the last 10 lines of messages and append new lines to the display as new lines are added to messages:

tail -f /var/adm/messages

To keeps following the log even when it is recreated, renamed, or removed as part of log rotation, at least BSD and GNU implementations provides a -F option which is useful in cases when the user is following a log file that rotates.

tail -F /var/adm/messages

To interrupt tail while it is monitoring, break-in with Ctrl+C. This command can be run "in the background" with &, see job control.

If the user has a command's result to monitor, the watch command can be used.

There is a GNU Emacs mode that emulates the functionality of tail -f, called auto-revert-tail-mode.

Variants

  • CCZE is tail-like while displaying its output in color
  • pctail Like CCZE: Python Colorized TAIL, a colorized tail made in python which tails and colorizes syslog output.
  • Inotail: is a deprecated implementation of inotify kernel interface. The early implementation of tail polled every second to see if new data can be displayed, as tail implemented inotifiy kernel interface Inotail become deprecated and it is not longer maintained. Inotail used the Linux kernel's inotify-interface introduced in version 2.6.13 on August 2005 so that it only checks for new data when there really is some.
  • MultiTail not only displays logfiles in colors, it can also merge, filter, scrollback and split a terminal window in subwindows. It is more or less a combination of tail, sed, watch, CCZE/pctail, grep, diff, Beeper and others.
  • References

    Tail (Unix) Wikipedia