Output the first N lines of a file.
low risk
head outputs the first 10 lines by default (or N lines with -n). Essential for quickly previewing large files without loading them entirely. Also useful for extracting file headers in scripts.
| Flag | Meaning |
|---|---|
-n --lines | Output the first N lines |
-c --bytes | Output the first N bytes |
head -n 20 /var/log/syslogView first 20 lines of syslog · explain & risk-check →head -1 data.csvCheck CSV header row · explain & risk-check →ls -lt | head -5Show 5 most recently modified files · explain & risk-check →Use `head -n -5 file.txt` (negative N) to print everything except the last 5 lines — a lesser-known but powerful trick.
Reference text is hand-written and may be incomplete — check man head for your version. Test destructive commands on a non-production system first.