head (Unix)

Head (English " head") is a program for Unix and Unix- like operating systems for the first several lines of a file. However, unlike a text editor, the user is not making changes to the file in the location with head. The counterpart of head is tail, which displays the last lines of a file.


The syntax of head resembles many other command-line programs:

Head [ switch ]

Normally head the first 10 rows are from a file. The switches can type (rows, bytes) and number of output can be selected.

Typical application examples

The following example returns the first 20 rows of from:

Head-n 20 Returns the first 15 bytes of all files that start with foo:

Head- c 15 foo * Exotic examples

Many earlier versions of Unix did not have the command, therefore, referred the documentation and books on sed:

Sed 5q foo Some Unix systems still use the old syntax. There, the -n option is not supported. Here, the following syntax must be used for the first 20 rows, or output the first 50 bytes.

Head -20 head- 50c This syntax is deprecated and does not correspond to the POSIX standard 1003.1-2001.