← All commands
THE COMMAND REFERENCE

tail

Print the last lines or bytes of files, or follow a growing file.

Last updated

Portable / common

Implementation-level reference; examples are not certified for every installed version.

Overview

tail prints the end of each file you name, ten lines by default. It is the usual tool for reading the newest log lines, and with -f it keeps watching a file as it grows.

Background

A tail command appeared in PWB Unix, the Programmer's Workbench, according to the FreeBSD and macOS manuals. Today the name covers GNU tail, the tail that macOS ships, and the tail applet in BusyBox. They agree on -n, -c, and -f, and differ on long options and on -F.

Examples

Print the last ten lines (all of a short file):

tail notes.txt

Print the last two lines:

tail -n 2 notes.txt

Print everything from line 3 onward:

tail -n +3 notes.txt

Print the last six bytes:

tail -c 6 notes.txt

Print the last line of several files; each is introduced by a header:

tail -n 1 app.log logs/server.log

Watch a log as new lines arrive; press Ctrl+C to stop:

tail -f app.log

Options

-n
Print this many lines. -n +3 instead starts at line 3 and prints the rest.

-c
Print this many bytes from the end.

-f
Keep the file open and print new data as it is appended. It never exits on its own; stop it with
Ctrl+C. It follows the open file, so a log that is rotated to a new file may need -F where
available.

Common mistakes

-n 3 means the last three lines, but -n +3 means start at line 3, a different thing. tail -f blocks, so do not use it where a script must continue. Do not use tail on a file that is also being rewritten from the start if you need a consistent snapshot.

Portability

-n, -c, and -f are in the Common examples. The Common examples were executed on GNU coreutils 9.11, macOS system tools, and BusyBox 1.37.0 (see the development guide for the exact check). The -f example is reviewed but not executed here because it never ends.

References

Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.