1/6

Files & folders · Read longer files

The first lines: head

head prints the first lines of a file: 10 unless you say otherwise. -n and a number choose how many.

Why: to peek at a long file (a log, a spreadsheet's header row) without flooding the screen.

How to type it: head -n 2 file.

Worked example

learner@shellstreak:~$ head -n 2 notes.txt
Call the plumber on Tuesday
Buy coffee beans

What the output means

  • The first two lines of notes.txt. The third line, Renew library card, isn't shown.

Common mistakes

  • Leaving out the number: head -n notes.txt treats notes.txt as the number and fails.
  • Expecting head to change the file. It only prints.

Tap Run to see just the first two lines of your notes.

Try it:head -n 2 notes.txt
learner@shellstreak: ~
Starting your practice shell…

You can also type in the terminal yourself. Try anything: you can't break it.

Go deeper: Basic terminal commands for beginners