Forever & AlwaysLINUX COMMAND ATLAS

LINUX COMMAND ATLAS · COMMAND GUIDE

Linux head command

Show the first lines of a file; use -n to choose how many.

GNU Coreutils

Syntax

Command form
head [OPTION]... [FILE]...

Common options

5 options
OptionWhat it does
-n, --lines=NUMPrint the first NUM lines (default 10).
-c, --bytes=NUMPrint the first NUM bytes.
-q, --quietNever print file headers.
-v, --verboseAlways print file headers.
-z, --zero-terminatedTreat NUL, rather than newline, as the line delimiter.

Usage examples

3 examples

Show the first lines of a file; use -n to choose how many.

head -n 20 access.log

Show the first 20 lines of a log.

head -n 20 app.log

Inspect the first 64 bytes of a file.

head -c 64 image.bin

Notes

When reading from a pipe, head exits after receiving enough input, which can stop upstream commands early.