head Command

Purpose

Displays the first few lines of a file.

Syntax

head-Count-c Number | -n Number ] [ -q ] [  -v ] [  ] [ -h ] [ File  ... ]

Description

The head command writes to standard output a specified number of lines or bytes of each of the specified files, or of the standard input. If no flag is specified with the head command, the first 10 lines are displayed by default. The File parameter specifies the names of the input files. An input file must be a text file. When more than one file is specified, the start of each file is in ==> filename <== format.

To display a set of short files, identifying each one, enter the following command:
head -9999 filename1 filename2...
Note: The standard input is used if no file parameters is specified or if - parameter is specified.

Flags

Table 1. Flags
Item Description
-Count Specifies the number of lines from the beginning of each specified file to be displayed. The Count variable must be a positive decimal integer. This flag is equivalent to the -n Number flag, but must not be used if portability is a consideration.
-c Number Specifies the number of bytes to display. The Number variable must be a positive decimal integer.
-n Number Specifies the number of lines from the beginning of each specified file to be displayed. The number variable must be a positive decimal integer. This flag is equivalent to the -Count flag.
-q, --quiet, or --silent Does not print headers that provide the file names.
-v or --verbose Prints headers that provide the file names.
--version Displays the version information
-h Displays help about the head command.

Exit status

This command returns the following exit values:

Table 2. Exit status
Item Description
0 Successful completion.
>0 An error occurred.

Examples

To display the first five lines of the Test file, enter the following command:

head -5 Test

or

head -n 5 Test