Tail (Unix)

Last updated
tail
Developer(s) Various open-source and commercial 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 or GPLv2 or MIT License
coreutils: GPLv3+

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.

Contents

Implementations

The version of tail bundled in GNU coreutils was written by Paul Rubin, David MacKenzie, Ian Lance Taylor, and Jim Meyering. [1] 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. [2] The FreeDOS version was developed by M. Aitchison. [3] A tail command is also part of ASCII's MSX-DOS2 Tools for MSX-DOS version 2. [4]

CCZE is tail-like while displaying its output in color. [5]

pctail is similar to CCZE. It is a colorized tail programmed in Python which tails and colorizes syslog output. [6]

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 in August 2005 so that it only checks for new data when there really is some. [7]

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.

Syntax

The command-syntax is:

tail [options] <filename>

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:

$ 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* 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 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 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 -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.

See also

Related Research Articles

uniq is a utility command on Unix, Plan 9, Inferno, and Unix-like operating systems which, when fed a text file or standard input, outputs the text with adjacent identical lines collapsed to one, unique line of text.

ls Command to list files and directories in Unix and Unix-like operating systems

In computing, ls is a command to list computer files and directories in Unix and Unix-like operating systems. It is specified by POSIX and the Single UNIX Specification.

head (Unix) Program on Unix and Unix-like systems

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

ln (Unix) Unix file management utility

The ln command is a standard Unix command utility used to create a hard link or a symbolic link (symlink) to an existing file or directory. The use of a hard link allows multiple filenames to be associated with the same file since a hard link points to the inode of a given file, the data of which is stored on disk. On the other hand, symbolic links are special files that refer to other files by name.

xargs is a command on Unix and most Unix-like operating systems used to build and execute commands from standard input. It converts input from standard input into arguments to a command.

dd is a command-line utility for Unix, Plan 9, Inferno, and Unix-like operating systems and beyond, the primary purpose of which is to convert and copy files. On Unix, device drivers for hardware and special device files appear in the file system just like normal files; dd can also read and/or write from/to these files, provided that function is implemented in their respective driver. As a result, dd can be used for tasks such as backing up the boot sector of a hard drive, and obtaining a fixed amount of random data. The dd program can also perform conversions on the data as it is copied, including byte order swapping and conversion to and from the ASCII and EBCDIC text encodings.

wc (Unix) Unix command utility

wc is a command in Unix, Plan 9, Inferno, and Unix-like operating systems. The program reads either standard input or a list of computer files and generates one or more of the following statistics: newline count, word count, and byte count. If a list of files is provided, both individual file and total statistics follow.

split is a utility on Unix, Plan 9, and Unix-like operating systems most commonly used to split a computer file into two or more smaller files.

paste is a Unix command line utility which is used to join files horizontally by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output.

nl is a Unix utility for numbering lines, either from a file or from standard input, reproducing output on standard output.

who (Unix)

The standard Unix command who displays a list of users who are currently logged into the computer.

rm (Unix) Unix command utility

rm is a basic command on Unix and Unix-like operating systems used to remove objects such as computer files, directories and symbolic links from file systems and also special files such as device nodes, pipes and sockets, similar to the del command in MS-DOS, OS/2, and Microsoft Windows. The command is also available in the EFI shell.

more (command) Terminal pager available on various operating systems

In computing, more is a command to view the contents of a text file one screen at a time. It is available on Unix and Unix-like systems, DOS, Digital Research FlexOS, IBM/Toshiba 4690 OS, IBM OS/2, Microsoft Windows and ReactOS. Programs of this sort are called pagers. more is a very basic pager, originally allowing only forward navigation through a file, though newer implementations do allow for limited backward movement.

In computing, tee is a command in command-line interpreters (shells) using standard streams which reads standard input and writes it to both standard output and one or more files, effectively duplicating its input. It is primarily used in conjunction with pipes and filters. The command is named after the T-splitter used in plumbing.

test is a command-line utility found in Unix, Plan 9, and Unix-like operating systems that evaluates conditional expressions. test was turned into a shell builtin command in 1981 with UNIX System III and at the same time made available under the alternate name [.

In computing, sleep is a command in Unix, Unix-like and other operating systems that suspends program execution for a specified time.

sort (Unix) Standard UNIX utility

In computing, sort is a standard command line program of Unix and Unix-like operating systems, that prints the lines of its input or concatenation of all files listed in its argument list in sorted order. Sorting is done based on one or more sort keys extracted from each line of input. By default, the entire input is taken as sort key. Blank space is the default field separator. The command supports a number of command-line options that can vary by implementation. For instance the "-r" flag will reverse the sort order.

The csplit command in Unix and Unix-like operating systems is a utility that is used to split a file into two or more smaller files determined by context lines.

<span class="mw-page-title-main">Command-line interface</span> Computer interface that uses text

A command-line interpreter or command-line processor uses a command-line interface (CLI) to receive commands from a user in the form of lines of text. This provides a means of setting parameters for the environment, invoking executables and providing information to them as to what actions they are to perform. In some cases the invocation is conditional based on conditions established by the user or previous executables. Such access was first provided by computer terminals starting in the mid-1960s. This provided an interactive environment not available with punched cards or other input methods.

cat (Unix) Unix command utility

cat is a standard Unix utility that reads files sequentially, writing them to standard output. The name is derived from its function to (con)catenate files. It has been ported to a number of operating systems.

References

  1. "tail(1): output last part of files - Linux man page". linux.die.net.
  2. "Native Win32 ports of some GNU utilities". unxutils.sourceforge.net.
  3. "ibiblio.org FreeDOS Package -- tail (Unix-like)". www.ibiblio.org.
  4. "MSX-DOS2 Tools User's Manual - MSX-DOS2 TOOLS ユーザーズマニュアル". April 1, 1993 via Internet Archive.
  5. "CCZE". freshmeat.sourceforge.net.
  6. "pctail". SourceForge.
  7. "distanz.ch - inotail". distanz.ch.
  8. Kalsi, Tajinder (2016). Practical Linux Security Cookbook. Packt Publishing Ltd. pp. 234–236. ISBN   9781785285301 . Retrieved 22 September 2017.