Peek at the start of a file
Preview files with head
⏱ Est. ~4 min
01 · Read
Sometimes a file is long and you only want to see the first few lines. That's exactly what head is for.
💡 Picture thisLike reading the first paragraph of a long article to check if it's what you're looking for.
Key points
- head shows the first 10 lines by default
- head -n 5 shows only the first 5 lines
- Great for previewing big files without flooding your screen
02 · Terminal exercise
This log file has 15 lines. Sometimes you just want a quick glance at the start, not the whole thing. head shows the first 10 lines by default.
(This section is interactive — please enable JavaScript.)
03 · Terminal exercise
You can control how many lines head shows with the -n flag. Want just the first 3 lines? Use -n 3.
(This section is interactive — please enable JavaScript.)
04 · Terminal exercise
A little trick: run head -n 1 on a CSV file and you'll see just the column headers. You learn what fields the file has without drowning in data.
(This section is interactive — please enable JavaScript.)
05 · Fill in the blank
To see only the first 5 lines of a file, you would type: head ___ 5 filename
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.