Script Valley
Linux & Bash for Developers
Text Processing & SearchingLesson 2.1

How to read and view files in Linux terminal

cat, less, more, head, tail, tail -f, file sizes, wc, viewing binary files

Reading Files Without Opening an Editor

You will spend a lot of time reading log files and configs on servers where no GUI editor exists. These commands are your toolkit.

cat, head, tail

cat dumps the entire file to stdout — fine for small files, awful for 100MB logs. head -n 20 shows the first 20 lines. tail -n 50 shows the last 50. For live log monitoring, tail -f is essential: it streams new lines as they are written.

# View entire file
cat /etc/hosts

# First 10 lines (default)
head /var/log/syslog

# Last 20 lines
tail -n 20 /var/log/nginx/error.log

# Follow a log file in real time (Ctrl+C to stop)
tail -f /var/log/nginx/access.log

# Count lines, words, bytes
wc -l /var/log/syslog

less — The Right Tool for Large Files

less opens a file in a pager: you can scroll with arrow keys, search with /pattern, and quit with q. It does not load the entire file into memory, so it handles gigabyte logs cleanly. Use less +F to combine pager navigation with live follow mode — press Ctrl+C to pause and scroll, then F to resume following.

less /var/log/auth.log
# Inside less: /error to search, n for next match, q to quit

Up next

grep command tutorial for searching files

Sign in to track progress