DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Managing files

Reading just the first or last lines of a file

Sometimes it is useful to see just the first few, or last few, lines in a file. If you want to see what is in a file without looking at the whole file, you may find the head command useful. The tail command, which looks at the last few lines, can be useful as well. For example, you could use tail to look at the latest information in a log file, a file that is being constantly updated by some program on the system.

To look at the first few lines of a file, type head filename, where filename is the name of the file you want to look at, and then press <Enter>. By default, head shows you the first 10 lines of a file. You can change this by typing head -number filename, where number is the number of lines you want to see.

For example, if you want to see the first 15 lines of /etc/passwd, you could type:

head -15 /etc/passwd

To look at the last few lines of a file, use the tail command. tail works the same way as head: type tail and the filename to see the last 10 lines of that file, or type tail -number filename to see the last number lines of the file.

Try using tail to look at the last five lines of your .profile or .login:

  1. Type tail -5 $HOME/.profile and press <Enter>.
    (C shell users: type tail -5 $HOME/.login and press <Enter>.)

  2. tail displays the last five lines of your .profile (or .login).
    % tail -5 $HOME/.login
    	setenv  TERMCAP  $term[2]   # terminal data base
    endif
    unset term noglob
    setenv PRINTER tpubs_lw1
    setenv WPVER lyrix6                 # default lyrix version
    

Next topic: Making directories
Previous topic: Reading a file one screen at a time

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005