Skip to content

head command

Show the first lines of a file.

On this page

Syntax

head [options] [file…]

Provided by the coreutils package. Run man head for the full manual.

Common options

OptionWhat it does
-n NShow the first N lines (default 10)
-n -NShow everything except the last N lines
-c NShow the first N bytes
-qDon't print file name headers

Examples

  1. First 10 lines

    head file.txt
  2. First 20 lines

    head -n 20 access.log
  3. All but the last 5 lines

    head -n -5 data.csv
  4. First 100 bytes

    head -c 100 file.bin
  5. Top 5 largest items in a directory

    du -sh * | sort -rh | head -5

head guides

← All Linux commands · Suggest a fix

Back to top