head Show the first lines of a file
Prints the first part of a file, ten lines by default. Use it to peek at a large file, check a CSV header, or take the top few results from another command.
Synopsis
head [-n count | -c bytes] [file ...]
Common options
| Option or form | What it does |
|---|---|
-n count | Print the first count lines instead of 10. Also written -n5 or, as a shorthand, -5 |
-c bytes | Print the first bytes bytes instead of lines. A multi-byte character can be cut in half |
-5 | Old shorthand for -n 5. Any number works. |
-n -count | GNU only: print everything except the last count lines. macOS head rejects it with an illegal line count error |
-q | GNU only: never print the ==> name <== header when given several files. macOS head has no -q |
-v | GNU only: always print the file name header, even for one file. macOS head has no -v |
Examples
head notes.txt
head -n 3 notes.txt
alpha
beta error
gamma
head -n 1 data.csv
name,team,score
head -n 2 notes.txt app.log
==> notes.txt <==
alpha
beta error
==> app.log <==
2026-01-01 INFO start
2026-01-01 ERROR failed to open
sort words.txt | uniq -c | sort -rn | head -n 2
head -n 3 notes.txt | tail -n 1
gamma
Notes
- With more than one file, head prints a header such as ==> notes.txt <== before each one. With a single file there is no header.
- The macOS head has only -n and -c. Scripts that use -q, -v or a negative count (head -n -3) work on Linux but fail on macOS. On macOS, sed '$d' drops only the last line.
- If a file has fewer lines than the count, head prints the whole file. It does not report an error.
- To see the end of a file instead, use tail. To page through a whole file, use less.
See also
Last reviewed 2026-10-07.