tail (Unix)

{{lowercase title}}

{{Infobox software

| name = tail

| logo =

| screenshot =

| screenshot size =

| caption =

| author =

| developer = Various open-source and commercial developers

| released =

| latest release version =

| latest release date =

| programming language = C

| operating system = Unix, Unix-like, V, Plan 9, Inferno, MSX-DOS, FreeDOS

| platform = Cross-platform

| genre = Command

| license = Plan 9: Lucent Public License or GPLv2 or MIT License
coreutils: GPLv3+

| website =

}}

{{code|tail}} is a program available on Unix, Unix-like systems, FreeDOS and MSX-DOS used to display the tail end of a text file or piped data.

Implementations

The version of {{code|tail}} bundled in GNU coreutils was written by Paul Rubin, David MacKenzie, Ian Lance Taylor, and Jim Meyering.{{Cite web |url=https://linux.die.net/man/1/tail |title=tail(1): output last part of files - Linux man page |website=linux.die.net}} The command is available as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.{{Cite web |url=http://unxutils.sourceforge.net/ |title=Native Win32 ports of some GNU utilities |website=unxutils.sourceforge.net}} The FreeDOS version was developed by M. Aitchison.{{Cite web |url=http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/repos/pkg-html/tail.html |title=ibiblio.org FreeDOS Package -- tail (Unix-like) |website=www.ibiblio.org}} A {{code|tail}} command is also part of ASCII's MSX-DOS2 Tools for MSX-DOS version 2.{{Cite web |url=https://archive.org/details/MSXDOS2TOOLS |title=MSX-DOS2 Tools User's Manual - MSX-DOS2 TOOLS ユーザーズマニュアル |date=April 1, 1993 |via=Internet Archive}}

CCZE is {{code|tail}}-like while displaying its output in color.{{Cite web |url=http://freshmeat.sourceforge.net/projects/ccze/ |title=CCZE |website=freshmeat.sourceforge.net}}

pctail is similar to CCZE. It is a colorized {{code|tail}} programmed in Python which tails and colorizes syslog output.{{Cite web |url=https://sourceforge.net/projects/pctail/ |title=pctail |website=SourceForge|date=25 February 2013 }}

Inotail was an implementation using the inotify 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 original {{code|tail}} did.{{Cite web |url=https://distanz.ch/inotail/ |title=inotail |website=distanz.ch}} However, newer versions{{which?|date=June 2024}} 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.{{cite book |last1=Kalsi |first1=Tajinder |title=Practical Linux Security Cookbook |date=2016 |publisher=Packt Publishing Ltd |isbn=9781785285301 |pages=234–236 |url=https://books.google.com/books?id=T_7fDAAAQBAJ&q=%22MultiTail%22 |access-date=22 September 2017 |language=en}} It is more or less a combination of tail, sed, watch, CCZE/pctail, grep, diff, Beeper and others.

Syntax

The command-syntax is:

tail [options]

By default, {{code|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:

$ tail -n1 report-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 -c4 report*

523

272

623

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

{{code|tail}} has two special command line option {{code|-f}} and {{code|-F}} (follow) that allows a file to be monitored. Instead of just displaying the last few lines and exiting, {{code|tail}} displays the lines and then monitors the file. As new lines are added to the file by another process, {{code|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 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 of messages and append new lines to the display as new lines are added to messages:

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 {{code|-F}} option which is useful in cases when the user is following a log file that rotates.

tail -F /var/adm/messages

To interrupt {{code|tail}} while it is monitoring, break-in with Ctrl+C. This command can be run "in the background" with {{code|&}}, 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 {{code|tail -f}}, called {{code|auto-revert-tail-mode}}.

See also

References

{{Reflist}}