Skip to content

head

8 commands

Prints the first lines or bytes of files — quick previews of logs and data.

  • text
  • files

Install head

sudo apt install coreutils

Basics5

head <file>

Prints the first 10 lines.

Link
head -n <n> <file>

Prints the first n lines.

Link
head -n -<n> <file>

Prints everything except the last n lines (GNU).

Link
head -c <bytes> <file>

Prints the first n bytes — useful for checking file headers.

Link
head -n 1 <file1> <file2>

Shows the first line of several files, each with a header naming the file.

Link

In pipelines3

<command> | head -n <n>

Keeps only the first lines of output — here the five most recently modified files.

Link
sort -rn <file> | head

A top-ten list from numeric data.

Link
head -c 16 /dev/urandom | xxd

Reads 16 random bytes and shows them in hex.

Link