link to content
Essentials at NC State Home
skip header navigation and go to content Help | ResNet | Computing@NC State | For OIT Staff | Publications | Search NC State | Feedback | Site Map
your unity account
antivirus & security
email & messaging
connections & labs
your computer
software@nc state
files
web pages
education & training
publications
other resources
troubleshooting
ITD Sections

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

jump back to content/page ends, begin footer
jump to content
jump to content Go to page top Page Top | Site Map | OIT | Policy Disclaimer | Site Survey