What are the essential commands for viewing files in Linux?
The core file-viewers are cat (whole file), head/tail (first/last lines), wc (counts), and file (what type it is) — pick by how much of the file you actually need to see.
The reason there are several tools instead of one is that "show me the file" has different shapes. Dumping a whole file is fine for a config but disastrous for a 2-GB log — so each command answers a different question:
| Command | Question it answers | Example |
|---|---|---|
cat |
"Show me everything." | cat /etc/hostname |
head |
"What's at the top?" (first 10 lines) | head -n 5 file |
tail |
"What's at the bottom?" (last 10 lines) | tail -n 50 file |
wc |
"How big is it?" (lines/words/chars) | wc -l file |
file |
"What kind of file is this?" | file /bin/ls |
The standout is tail -f ("follow"):
tail -f /var/log/messages # keep printing new lines as they're written
This doesn't exit — it stays open and streams new lines live. It's the single most-used command for watching a log while you reproduce a problem, because you see errors appear the instant they happen.
Gotcha: cat on a binary file spews control characters that can garble or even hang your terminal. Run file first when you're unsure — that's exactly what it's for. (If your terminal does get scrambled, type reset and press Enter.)
Go deeper:
GNU Coreutils Manual — documents
cat,head,tail,wcand the rest of the core utilities.