text

head

Outputs the first part of files. Defaults to the first ten lines but can trim by any line or byte count.

head [OPTION]... [FILE]...

Common flags

Flag Purpose
-n Print the first N lines (use -n -N to skip the last N)
-c Print the first N bytes
-q Never print filename headers with multiple files
-v Always print filename headers

Examples

head file.txt

First 10 lines

head -n 50 log.txt

First 50 lines

head -c 1K file.bin

First 1024 bytes

head -n -5 report.txt

All lines except the last 5

Gotcha

Old scripts sometimes use head -N (a single dash and number); modern GNU head still accepts it but prefer -n N for portability.

Related commands

← All Linux commands · Linux cheat sheet