[Previous] [Contents] [Next]

tail

Copy the last part of a file (POSIX)

Syntax:

tail [-c|-l] [-f] [-n number] [-n] [file]

Options:

-c
Measure the quantity of output in bytes.
-f
If the input file is a regular file (i.e. not a tty or FIFO), don't terminate after the last line of the input file has been copied, but enter a continuous loop. The tail utility then sleeps for approximately one second, then attempts to read and copy further bytes from the input file.
-l
("el") Measure the quantity of output in lines; this is the default unit of measure.
-n number
Copy output using this number of lines (default) or bytes. The number argument is a decimal integer whose sign specifies the location in the file to begin copying:
If the sign is:  Then copying starts relative to the:
+ beginning of the file
- end of the file
none end of the file
If you omit the -n number option, the default is -10 (the number ten) i.e. the last ten units (lines or bytes) of the file.
-n
(Obsolescent) A historical version of -n number. e.g. -20 is equivalent to -n 20.
file
The pathname of an input file. If you don't specify a file, the standard input is used.

Description:

The tail utility copies its input file to the standard output, beginning at a designated place.

Copying begins at the point in the file indicated by the -n number option. The argument number is counted in units of lines or bytes, according to the -l and -c options.

When tail is applied to a non-seekable file (e.g. a tty), tail must maintain an internal buffer. This buffer is large enough to hold at least 10 lines of characters.

Examples:

You can use the -f option to monitor the growth of a file that is being written by a process. For example, the command:

    tail -f fred

prints the last ten lines of the file fred, followed by any lines that are appended to fred between the time tail is initiated and terminated. As another example, the command:

    tail -cf -n 15 fred

prints the last 15 bytes of the file fred, followed by any lines that are appended to fred between the time tail is initiated and terminated.

Exit status:

0
Successful completion.
>0
An error occurred.

See also:

cat, head, more, less


[Previous] [Contents] [Next]