UnixDroid

Text · Linux command

head command in Linux

What does head do?

head shows the first lines of a file — 10 by default, or any number with -n.

head [-n N] file

Most useful options

OptionWhat it does
-n Nshow the first N lines
-c Nshow the first N bytes

head examples

$ head file.txt Try it ›

first 10 lines

$ head -n 3 access.log Try it ›

first 3 lines

$ sort -nr counts.txt | head -5 Try it ›

top 5

In security work

head -c 16 file | xxd shows a file's "magic bytes", revealing its real type whatever its extension.

Questions about head

How do I show the first 20 lines?

head -n 20 file