Quiz Entry - updated: 2026.07.14
How do you read and display file contents from the command line?
cat dumps the whole file, head/tail show the first/last lines, and less pages through big files one screen at a time.
Pick the tool by file size and intent: cat is fine for short files but floods your terminal with a large one. head/tail peek at the ends (great for log files — tail -f even follows new lines live as they're written). less is the safe default for anything big because it doesn't load the whole file into memory — it streams pages on demand, with search (/) and scrolling built in.
Common file viewing commands:
| Command | Purpose |
|---|---|
cat file |
Display entire file |
head file |
First 10 lines |
head -n 5 file |
First 5 lines |
tail file |
Last 10 lines |
tail -n 20 file |
Last 20 lines |
tail -f file |
Follow file updates |
less file |
Paginated viewer |
more file |
Simple pager |
Combining with pipes:
# First 10 users from passwd:
head -n 10 /etc/passwd
# Last 2 users:
cat /etc/passwd | tail -n 2
# Follow log in real-time:
tail -f /var/log/syslog
Less navigation:
Space= next pageb= previous page/pattern= searchq= quit
Tip: Use less for large files - it doesn't load the entire file into memory!