head

head prints the beginning of a file — by default, the first 10 lines.

head [options] [file...]
$ head config.toml

It is the quick way to glance at the top of a file without printing the whole thing — a header, the first few records, the start of a log. With no file, head reads standard input.

Choosing how much #

OptionEffect
-n, --lines=NUMPrint the first NUM lines instead of 10.
-c, --bytes=NUMPrint the first NUM bytes instead of counting lines.

NUM accepts a unit suffix (K, M, …) when counting bytes.

Counting from the end #

If NUM is given a leading -, the meaning flips: head prints everything except the last NUM.

$ head -n -5 report.txt    # all but the final 5 lines

Headers for multiple files #

When given more than one file, head prints a header line before each one so you can tell them apart. Two options override that:

OptionEffect
-q, --quietNever print the file-name headers.
-v, --verboseAlways print the header, even for a single file.

Other options #

OptionEffect
-z, --zero-terminatedTreat the NUL character as the line delimiter instead of newline.

Exit status #

CodeMeaning
0Every file was printed.
1A file could not be read.

Edit this page