Skip to content

The head command

Print the first lines of files. Prints the first 10 lines of each file, or of what is piped into it. With more than one file, each part starts with a ==> name <== header.

Usage

head [OPTION]... [FILE]...

Options

-n N, --lines=Nthe first N lines instead of 10
-n -Neverything except the last N lines
-Nshort for -n N

Examples

  • head notes.txtThe first 10 lines
  • head -n 3 notes.txtThe first 3 lines
  • sort scores.txt | head -n 5The five lowest

Learn it step by step

learner@sandbox: ~bash (practice)
Note: Try head here: your home directory has sample files. Press Try beside an example, or type your own.

A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.