📖 How to View Files in Linux Terminal
Learn which Linux command to choose for viewing text files, logs, and configurations.
Comparison of Linux File Viewing Commands
| Command | Best For | Key Advantage |
|---|---|---|
cat | Small text files (< 100 lines) | Dumps entire content immediately to stdout |
less | Large files & source code | Interactive paging, forward/backward search (/), does not load entire file into memory |
head | Checking headers or file start | Displays first 10 lines (configurable via -n 50) |
tail | Recent log entries | Displays last 10 lines (configurable via -n 20) |
tail -f | Live monitoring server logs | Follows active log writes in real-time |
nano / vim | Editing & full inspection | Terminal text editors for modifying content |
1. Viewing with less (Recommended for Large Files)
$ less /var/log/syslog
Navigation keys: Space (next page), b (previous page), /pattern (search text), q (quit).
2. Monitoring Live Logs with tail -f
$ tail -f /var/log/nginx/access.log
As incoming requests hit Nginx, new log entries stream directly to your terminal screen. Press Ctrl+C to stop.