head

See the start of a file or of any command's output: the first 10 lines, or exactly as many as you want.

>_ Try it: a simulated Linux, right here
Loading the terminal…

Examples

  • head app.log
  • head -n 3 app.log
  • head -n 1 users.csv
  • ls /etc | head -n 3
  • head -n 2 app.log users.csv

How it works

head FILE prints the first 10 lines of a file — handy for a quick look at a big log or a CSV without scrolling through all of it.

Choose how many with -n: head -n 3 app.log. It also reads a pipe, so ls /etc | head -n 3 shows just the first three names.

Syntax

head [-n LINES] [FILE]...

Options

OptionWhat it does
-n Nshow N lines instead of 10
-Nthe short form: head -3 is head -n 3

Good to know

  • head shows the start, tail the end: together they cover most "what is in this file?" questions.
  • head -n 1 users.csv is the quickest way to see which columns a CSV has.