| tail | |
|---|---|
| Developers | Variousopen-source andcommercial developers |
| Written in | C |
| Operating system | Unix,Unix-like,V,Plan 9,Inferno,MSX-DOS,FreeDOS |
| Platform | Cross-platform |
| Type | Command |
| License | Plan 9:Lucent Public License orGPLv2 orMIT License coreutils:GPLv3+ |
tail is aprogram available onUnix,Unix-like systems,FreeDOS andMSX-DOS used to display the tail end of a textfile orpiped data.
The version oftail bundled inGNUcoreutils was written by Paul Rubin, David MacKenzie, Ian Lance Taylor, and Jim Meyering.[1] The command is available as a separate package forMicrosoft Windows as part of theUnxUtils collection ofnativeWin32ports of common GNU Unix-like utilities.[2] TheFreeDOS version was developed by M. Aitchison.[3] Atail command is also part ofASCII'sMSX-DOS2 Tools forMSX-DOS version 2.[4]
CCZE istail-like while displaying its output in color.[5]
pctail is similar to CCZE. It is a colorizedtail programmed inPython which tails and colorizes syslog output.[6]
Inotail was an implementation using theinotify Linux kernel interface (introduced in version 2.6.13 in August 2005) to check whether new data is available instead of polling every second, as the originaltail did.[7] However, newer versions[which?] of tail also started using inotifiy when possible, so Inotail became deprecated and is not longer maintained.
MultiTail not only displays logfiles in colors, it can also merge, filter, scrollback and split a terminal window into subwindows.[8] It is more or less a combination of tail,sed,watch, CCZE/pctail,grep,diff, Beeper and others.
The command-syntax is:
tail [options] <filename>
By default,tail will output the last 10 lines of its input to thestandard output. Withcommand 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:
$tail-n1report-13*==> report-1301 <==Total tons output for month of January '13 was 523==> report-1302 <==Total tons output for month of February '13 was 272==> report-1303 <==Total tons output for month of March '13 was 623
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.
$tail--silent-c4report*523272623
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 offilename can be shown with the following command:
tail -20filenametail -50cfilename
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, useman pages on the running system for specific options and actions.
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 anotherprocess,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 theGNU coreutils as of version 7.5 support theinotify infrastructure introduced in Linux kernel version 2.6.13 in August 2005 which only check the file when is notified of changes by the kernel.
The following command will display the last 10 lines ofmessages and append new lines to the display as new lines are added tomessages:
tail -f /var/adm/messages
To keep following the log even when it is recreated, renamed, or removed as part of log rotation, at least BSD and GNU implementations provide a-F option which is useful in cases when the user is following a log file thatrotates.
tail -F /var/adm/messages
To interrupttail while it is monitoring, break-in with Ctrl+C. This command can be run "in the background" with&, seejob control.
If the user has a command's result to monitor, thewatch command can be used.
There is aGNU Emacs mode that emulates the functionality oftail -f, calledauto-revert-tail-mode.