Paging with less, head & tail
less scrolls through big files one page at a time; head and tail show just the start or end.
less file
head -n N file
tail -f fileLarge files would scroll off the screen with cat. These three commands solve that.
less — scroll a file
less file opens a scrollable view. Use the arrow keys or Space to page down, /word to search, and q to quit.
head — the first lines
head file shows the first 10 lines. Use -n 20 for a different count.
tail — the last lines
tail file shows the last 10 lines. The killer option is -f ("follow"), which keeps the file open and prints new lines as they are added — perfect for watching logs live.
Example
# Scroll a long file (press q to quit)
less /var/log/syslog
# First 5 lines
head -n 5 access.log
# Last 20 lines
tail -n 20 access.log
# Watch a log update live
tail -f /var/log/nginx/access.logWhen to use it
- A sysadmin uses 'less /var/log/syslog' to scroll through thousands of log lines without loading the entire file into memory.
- A developer pipes 'git log | less' so they can browse commit history with keyboard navigation.
- An ops engineer uses 'less +F /var/log/app.log' to follow live log output, equivalent to 'tail -f' but with scroll-back.
More examples
Page through a large file
Opens a large file in less and lists the essential navigation keys for paging and searching.
less /var/log/syslog
# Space = page down
# b = page up
# q = quit
# /word = search forwardSearch within less
Shows the search commands inside less that let you find and filter log entries interactively.
less /var/log/auth.log
# Inside less, type:
# /Failed - search forward for 'Failed'
# n - next match
# N - previous match
# &Failed - filter to show only matching linesFollow live log output
Uses the +F flag to tail a live file inside less, allowing you to pause and scroll through history.
# Follow file as it grows (like tail -f but scrollable)
less +F /var/log/nginx/access.log
# Press Ctrl+C to stop following, then scroll back
# Press F again to resume following
Discussion