Think of reading a book in a library. Sometimes you just glance at a short postcard, sometimes you flip through pages carefully without writing in the margins, and sometimes you only check the first page or the very last page to see how the story ends.
On a Linux server, opening a text file in an editor when you only want to read it can feel risky—one accidental keystroke could change a setting. Instead, Linux gives you four safe, read-only commands: cat, less, head, and tail.
1. cat: Best for Short Notes
The cat command dumps the entire file straight onto your screen. It is perfect for tiny files like a 10-line config or a quick note:
# Print a short text file all at once
cat notes.txt
2. less: Scroll Safely Through Long Files
If a file has thousands of lines, cat will scroll past in a blur. Use less to open the file one screen at a time. Press Space to go down, b to go back, and q to quit cleanly:
# Open a long log file page by page without editing it
less /var/log/syslog
3. head and tail: Peek at the Top or Bottom
When you only need the first few lines (like column headers) or the newest lines at the bottom of a log file, head and tail save you from scrolling:
# Show the first 10 lines of a file
head -n 10 access.log
# Show the last 15 lines of a file
tail -n 15 access.log
# Watch new log lines appear live (press Ctrl+C to stop)
tail -f access.log
3 Things to Remember
- Read-only means zero risk: None of these four commands can accidentally modify or delete your file.
- Pick the tool by file size: Use
catfor short files, andlessfor long files so you can scroll comfortably. - Use
tail -ffor live logs: It lets you watch server activity happen in real time, andCtrl+Cexits safely.