Reading just the first or last lines of a file (2024)

DOC HOMESITE MAPMAN PAGESGNU INFOSEARCHPRINT BOOK

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

To look at the first few lines of a file, typehead filename, where filenameis the name of the file you want to look at, and then press<Enter>. By default, head shows you the first 10lines of a file. You can change this by typing head-number filename, wherenumber 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 thetail command. tail works the same wayas head: type tail and the filename tosee the last 10 lines of that file, or typetail -number filename to see the lastnumber lines of the file.

Try using tail to look at the last five lines ofyour .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/.loginsetenv TERMCAP $term[2] # terminal data baseendifunset term noglobsetenv PRINTER tpubs_lw1setenv WPVER lyrix6 # default lyrix version
Next topic: Making directories
Previous topic: Reading a file one screen at a time

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003

Reading just the first or last lines of a file (2024)
Top Articles
Latest Posts
Article information

Author: Pres. Lawanda Wiegand

Last Updated:

Views: 6367

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Pres. Lawanda Wiegand

Birthday: 1993-01-10

Address: Suite 391 6963 Ullrich Shore, Bellefort, WI 01350-7893

Phone: +6806610432415

Job: Dynamic Manufacturing Assistant

Hobby: amateur radio, Taekwondo, Wood carving, Parkour, Skateboarding, Running, Rafting

Introduction: My name is Pres. Lawanda Wiegand, I am a inquisitive, helpful, glamorous, cheerful, open, clever, innocent person who loves writing and wants to share my knowledge and understanding with you.