How to View the Start of a File in Linux (head)

head prints the first lines of a file, by default the first 10.

Published October 3, 2026

head prints the first lines of a file (10 by default). Use -n to choose the number of lines or -c for bytes.

How it works

Useful to peek at big files, headers of CSVs or the top results of a pipeline.

Negative counts like -n -5 print everything except the last 5 lines (GNU).

Try it

head -n 3 data.csv
id,name,city
1,Ada,Pune
2,Bob,Delhi

Practical examples

First 20 lines

head -n 20 app.log

Top 5 results

sort -rn counts.txt | head -5

First bytes

head -c 100 file.bin

Middle lines

sed -n '20,30p' file.txt

Common mistakes

  • Opening multi-GB files in an editor instead of using head.
  • Forgetting that head stops early and can cause SIGPIPE upstream.
  • Assuming negative -n works on macOS.

Key takeaways

  • head shows the start.
  • -n for lines.
  • Pair with tail for ranges.

FAQ

Opposite of head?

tail.

View a range?

sed -n 'x,yp' or head | tail.

More Linux articles