Preview the start of a file with head
head is the mirror of tail for reading the top of a file, and its -n and -c flags work equally well on files and on piped command output.
Run `head -n 20 huge.csv` to print the first 20 lines, or `head -c 512 file` for the first 512 bytes.
01Command
Command
$ head -n 20 huge.csv
ps aux | head -5
head -c 512 binary.bin | xxd02What it does
head reads ten lines by default; -n sets the line count and -c works in bytes, which is the right mode for inspecting binary files safely. Piping any verbose command into `head -5` is the quickest way to cap its output, and combining `head` with several files interleaves them with ==> filename <== headers.
03Risk
!Warning: When several files are named, head prints headers between them — scripts parsing its output should pass exactly one file.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- head — display the first lines of a fileEvidence: Documents -n for line count and -c for byte count.
Last verified: 2026-09-17 · Category: Files & Folders