Look Inside Files Without Opening Them
Sometimes you just want to see what's in a file — without opening an app, without leaving Terminal.
There are several commands for this, depending on what you need.
cat: Show Everything
cat dumps the entire contents of a file to your screen:
View a text file:
cat ~/.zshrc
The entire file scrolls past. Good for short files. For long files, it's overwhelming.
What does "cat" stand for? "Concatenate." Originally meant for joining files together, but mostly used to display file contents.
head: Just the Beginning
head shows just the first 10 lines:
View the first 10 lines:
head ~/.zshrc
Or specify how many lines:
head -20 ~/.zshrc
tail: Just the End
tail shows the last 10 lines. Useful for log files where the newest entries are at the bottom:
View the last 10 lines:
tail ~/.zshrc
less: Browse a Long File
less opens a file in a scrollable viewer. You can move up and down:
Open a file in the viewer:
less ~/.zshrc
Use ↑ / ↓ or Space to scroll
Press q to quit
Key Takeaway
cat for short files, head/tail for beginnings/endings, less for browsing long files. Press q to exit less.