tail

tail prints the end of a file — by default, the last 10 lines.

tail [options] [file...]
$ tail server.log

It is the counterpart of head: the quick way to see the most recent lines of a file. With no file, tail reads standard input.

Choosing how much #

OptionEffect
-n, --lines=NUMPrint the last NUM lines instead of 10.
-c, --bytes=NUMPrint the last NUM bytes instead of counting lines.

If NUM is given a leading +, the meaning flips: tail prints everything from line NUM onward.

$ tail -n +20 report.txt    # from line 20 to the end

Following a growing file #

tail's most useful trick is -f. Instead of printing the end and exiting, it stays running and prints new lines as they are appended — the standard way to watch a log file live.

OptionEffect
-f, --followKeep the file open and print new data as it is added.
-FFollow the file by name, and keep retrying if it is missing. Equivalent to --follow=name --retry. This survives log rotation — when the file is replaced, -F picks up the new one.
--retryKeep trying to open a file that is not yet accessible.
--pid=PIDWhile following, stop once process PID exits.
-s, --sleep-interval=NWait N seconds between checks of the file.

Press Ctrl-C to stop a tail -f.

Headers for multiple files #

As with head, when given more than one file tail prints a header before each.

OptionEffect
-q, --quietNever print the file-name headers.
-v, --verboseAlways print the header, even for a single file.

Other options #

OptionEffect
-z, --zero-terminatedTreat the NUL character as the line delimiter instead of newline.

Exit status #

CodeMeaning
0Success.
1A file could not be read.

Edit this page