head prints just the start of a file. Learn the default of ten lines, how to set the count with -n, and what happens with several files, by running the commands in a real terminal in your browser.
Updated: 2026-09-05
head [options] file...
Prints the beginning of a file. Without a count, that means ten lines.
The terminal on this page has a log file with 30 lines in it.
$ head logs/app.log
line 01
line 02
line 03
line 04
line 05
line 06
line 07
line 08
line 09
line 10
Thirty lines in the file, ten on your screen. That is the default.
-n takes the count.
$ head -n 3 logs/app.log
line 01
line 02
line 03
This is the everyday way to look at a file with a header row.
$ head -n 2 users.csv
id,name
1,ada
That is usually enough to know what you are dealing with.
Pass more than one and each gets a heading.
$ head -n 2 users.csv notes.txt
==> users.csv <==
id,name
1,ada
==> notes.txt <==
buy milk
call the bank
head is how you check the shape of something without reading all of it.
| Situation | What you type |
|---|---|
| Check the column names of a CSV | head -n 1 users.csv |
| See how a log starts | head -n 20 app.log |
| Peek at the top of a long listing | ls -l | head |
| Guess a file format | head -c 100 data.bin |
-c cuts by bytes rather than lines.
$ head -c 20 logs/app.log
line 01
line 02
line
head for the oldest, tail for the newest.
Logs grow downwards, so what is happening right now is at the end.
Reach for head only when you care about how something started.
The number is a count, not a line number.
head -n 3 means the first three lines, not the third line.
Order matters around a pipe.
head file | grep x searches the beginning of the file, while grep x file | head shows the first of the matches.
Which one you want depends on what you are narrowing.
webterm.appthis site
Advanced Terminal Commands
Learn commands for specific situations
learn.webterm.appa separate site

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.
See the course