This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Head" Unix – news ·newspapers ·books ·scholar ·JSTOR(June 2020) (Learn how and when to remove this message) |
| head | |
|---|---|
Example usage of head command to display first 5 lines ofLorem ipsum in the specified file | |
| Developers | Variousopen-source andcommercial developers |
| Operating system | Unix,Unix-like,MSX-DOS,IBM i |
| Platform | Cross-platform |
| Type | Command |
| License | coreutils:GPLv3 |
head is aprogram onUnix andUnix-likeoperating systems used to display the beginning of a textfile orpiped data.
The commandsyntax is:
head [options]⟨file_name⟩By default,head will print the first 10 lines of its input to thestandard output.
head -n 20filename
This displays the first 5 lines of all files starting withfoo:
head -n 5foo*Most versions[citation needed] allow omitting
n and instead directly specifying the number:-5.GNU head allows negative arguments for the-n option, meaning to print all but the last - argument value counted - lines of each input file.Many early versions of Unix and Plan 9 did not have this command, and documentation and books usedsed instead:
sed 5qfilename
The example prints every line (implicit) and quit after the fifth.
Equivalently,awk may be used to print the first five lines in a file:
awk 'NR < 6'filename
However, neither sed nor awk were available in early versions ofBSD, which were based onVersion 6 Unix, and included head.[1]
Ahead command is also part ofASCII'sMSX-DOS2 Tools forMSX-DOS version 2.[2] Thehead command has also been ported to theIBM i operating system.[3]