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
tail [ +-[number][lbcr] ] [file]
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
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:
ls -l | tail
To save this information in a file in the current directory named
mylist, at the Unix prompt, enter:
ls -l | tail > mylist
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?
This is document acrj in the Knowledge Base.
Last modified on 2008-10-02 00:00:00.
- Fill out this form to submit your issue to the UITS Support Center.
- Please note that you must be affiliated with Indiana University to receive support.
- All fields are required.