In Unix, how can I display the last lines of a file?
Use the Unix command
tail to read from
standard input or a file and send the result to standard output (i.e.,
your terminal screen). The format for using the
Everything in brackets is an optional argument. If you don't specify
tail uses standard input.
Tail begins at distance
+number from the
-number from the end of the input. The
number is counted in units of lines, blocks, or characters, according
to the appended options
-c. When you don't specify a unit,
operates based on lines.
tail to print lines
from the end of the file in reverse order. The default for
-r is to print the entire file this way. Specifying
tail not to quit at the end of the
file, but rather to reread the file repeatedly (useful for watching a
"growing" file such as a log file).
For example, given a file containing the English alphabet with each letter on a separate line, the command:tail -3 alphabetfile
would report:x y z
You can use
tail with pipes. For example, to see the
sizes of the last few files in the current directory, you could enter
at the Unix prompt:
To save this information in a file in the current directory named
mylist, at the Unix prompt, enter:
For more detailed information on
tail, consult the Unix
manual page by entering at the prompt:
At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?
Last modified on October 02, 2008.