head (Unix)
head (English for "head") is a program for Unix and Unix-like operating systems to output the first lines of a file. The opposite of head
is tail
, which shows the last lines of a file.
Working method
The syntax of head
many other command line programs is similar :
head [Schalter] <Dateiname>
Usually prints head
the first 10 lines of a file. The switches can be used to select the type (lines, bytes) and number of output.
Typical application examples
The following example outputs the first 20 lines of <Dateiname>
:
head -n 20 <Dateiname>
Outputs the first 15 bytes of all files that begin with foo :
head -c 15 foo*
Exotic examples
Many previous Unix versions didn't have the command, so documentation and books referred to sed :
sed 5q foo
Some Unix systems still use the old syntax. The option is -n
not supported there. The following syntax must be used here to output the first 20 lines or the first 50 bytes.
head -20 <Dateiname> head -50c <Dateiname>
This syntax is out of date and does not correspond to the POSIX standard 1003.1-2001.
Web links
-
head
: copy the first part of files - Open Group Base Specification -
head(1)
: display first few lines of files - OpenBSD General Commands Manual -
head(1)
: print the first part of files - Debian GNU / Linux executables or shell commands man page