Module 63 head

Previous Table of Contents Next


Module 63
head

DESCRIPTION

The external head command displays the first few lines of a file. It displays however many lines you specify as an option. If you do not specify the number of lines to display, head defaults to ten. Its cousin is the tail command.

COMMAND FORMAT

The format of the head command follows .

 head [ -n ] file 

Options

The following describes the option used to control how head functions.

- n The number of lines t display at the beginning of each file.

Arguments

The following describes the argument that may be passed to the head command.

file_list One or more files to be displayed by head. If the - n is specified, it applies to all files in the file_list .

FURTHER DISCUSSION

If more than one file is specified on the command line, head precedes each file with a line like:

 ===> filename <=== 

If only one file is given on the command line, head does not inform you of the filename being displayed.

You may choose to use head to display the entire contents of multiple short files so each file will be preceded by its filename. The following command provides an example:

 cj> head -999 file1 file2 file3 

RELATED COMMANDS

Refer to the cat , pg , pr , sed , and tail commands described in modules 13, 103, 105, 117, and 131, respectively.

RELATED FILES

The head command can read from a file or from the standard input. The head command writes to the standard output. It can therefore be used at the beginning of a pipe. Its output can be redirected to a desired file.

APPLICATIONS

The head command is useful for verifying what type of data is in a file. It can be used to view the first few lines of an ASCII file to visually decide what data is contained in the file. You might consider head as a special version of the cat command, allowing § you to view the beginning portion of the file.

TYPICAL OPERATION

In this activity yoy use the head command to display the first 15 lines of the /etc/passwd file. Begin at the shell prompt.

1.    Type head -15 /etc/passwd and press Return . Your screen scrolls up as the first 15 lines of the password file are displayed.
2.     Turn to Module 131 to continue the learning sequence.


Previous Table of Contents Next

Copyright Wordware Publishing, Inc.


Illustrated UNIX System V
Illustrated Unix System V/Bsd
ISBN: 1556221878
EAN: 2147483647
Year: N/A
Pages: 144
Authors: Robert Felps

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net