Viewing a file (cat, more, head, tail)
Unix includes several utilities for viewing files:
- cat displays a file on the screen in its entirety.
- more displays a file, pausing after each screen of
information.
- head shows the beginning lines of a file.
- tail shows the last lines of a file.
You can use either the cat or the more command
to display the entire contents of files on the screen. The cat command
displays entire files on the screen without pausing. The more command
pauses after each screen of information (approximately 23 lines) and displays
a menu that enables you to page forward or backward, search for text or
quit.
The syntax for cat and more is
cat filename
more filename
The head and tail commands are useful
when you want to view only the first or last portions of files. The syntax
for these commands is
head -n filename
tail -n filename
You can include the option -n to specify the number of lines head and tail will
display. If you do not include this option only the first or last ten lines
are displayed.
For example:
tail -14 meetingnotes
displays the last fourteen lines of the file "meetingnotes".
You can view more than one file at a time when using head or tail.
For example, if you enter:
head -14 .mylogin .mycshrc
the system will display the first 14 lines of each file.
Last modified
July 20, 2004
by cawalker
|