← Files & Text
Linux · Files & Text

How to view file contents in Linux

View files with cat, less, head, and tail, including following a growing log with tail -f and -F.


Read a file contents. less is the pager for big files; head and tail show the ends; tail -f follows a file as it grows, which is handy for logs.

# Whole file
cat <file>

# Page through a big file (q to quit, / to search)
less <file>

# First / last 20 lines
head -n 20 <file>
tail -n 20 <file>

# Follow a growing log
tail -f /var/log/messages

# Follow, surviving log rotation
tail -F /var/log/messages
LinuxtailFiles