A huge part of working on Linux is simply reading files: configuration files, logs, source code, CSV exports. You rarely need an editor just to look. This lesson covers the four classic viewers—cat, less, head and tail—plus wc for quick statistics, and shows when each tool is the right choice.
cat (concatenate) dumps a file straight to the screen:
cat /etc/hostname
cat notes.txt
cat -n script.sh # -n adds line numbers
cat part1.txt part2.txt # print several files back to backcat is perfect for short files. For a 10,000-line log it floods your terminal—that is what less is for. True to its name, cat can also concatenate files together, which becomes powerful once you learn redirection: cat part1.txt part2.txt > whole.txt.
less opens a file in a scrollable, searchable viewer without loading the whole file into memory, so it handles gigabyte logs effortlessly:
less /var/log/syslogEssential keys inside less:
If a command like git log or man ls drops you into a scrolling view, that is less—the same keys apply everywhere.
head shows the beginning of a file, ten lines by default:
head /etc/passwd
head -n 3 data.csv # just the first 3 lines
head -c 100 file.bin # first 100 byteshead -n 1 data.csv is the classic way to peek at a CSV header row before processing the file.
tail is the mirror image, showing the end of a file—which is where the newest entries of any log live:
tail /var/log/syslog
tail -n 50 app.log # last 50 lines
tail -f app.log # follow: stream new lines as they arrive
tail -f app.log | grep -i error # follow, but only show errorstail -f (follow) is one of the most used commands in real operations work: start it, trigger your application, and watch log lines appear live. Press Ctrl+C to stop following.
wc -l access.log # number of lines
wc -w essay.txt # number of words
wc -c photo.jpg # number of byteswc -l answers questions like "how many entries are in this log?" instantly.
| Situation | Tool |
|---|---|
| Short config file | cat |
| Long file, need to search or scroll | less |
| Check a CSV header or file format | head |
| Latest log entries | tail -n 50 |
| Watch a log live | tail -f |
| How big is this file? | wc -l or ls -lh |
cat /etc/os-release
head -n 5 /etc/passwd
tail -n 5 /etc/passwd
wc -l /etc/passwd
less /etc/services # practice /search, g, G, then q to quitAll of these files are safe, world-readable system files—perfect practice material on any Linux machine.
cat prints whole files; ideal for short ones and for concatenating.less is a fast, searchable pager: / to search, q to quit.head and tail show the start and end; -n controls how many lines.tail -f streams a growing log in real time—indispensable for debugging.wc -l counts lines for instant file statistics.Next lesson: File Permissions and chmod — understand who can read, write and execute your files.