Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

less Command Guide for Viewing Long Files Page by Page

less displays text one screen at a time and lets you scroll, search, and jump around without loading the whole file — the safe way to read anything long.


What is less, and Why Use It?

less is a pager: it opens a file for reading without dumping it all at once. Unlike cat, it pauses at each screen, and unlike more, it can scroll in both directions and search forwards and backwards.

The name is a recursive joke — “LESS is more than MORE” — and the tool lives up to it: it’s the standard way Linux users read files.

Why Learn less?

  • Files are longer than your screen. Logs, configs, man pages — less handles all of them.
  • You need to search while reading. /pattern jumps to matches; n steps through them.
  • It doesn’t load the whole file first, so opening a multi-gigabyte log is instant.
  • Everything pipes into it. command | less is the universal way to inspect any long output.

The single most useful habit in this wiki: put | less after any command whose output might be long. You can always press q to quit.


1. Open a File

less filename.txt

Example:

less /var/log/syslog
  • The file opens at the top. Nothing is loaded beyond the first screen — perfect for huge files.

2. Navigate

While less is open:

KeyAction
Space / PageDownOne page down
b / PageUpOne page up
↓ / EnterOne line down
↑One line up
gJump to the beginning
GJump to the end

Example:

less large-file.log
  • Press G to see the last lines instantly — the pager equivalent of tail.

KeyAction
/wordSearch forward for word
?wordSearch backward for word
nRepeat the search in the same direction
NRepeat the search in the opposite direction

Example:

less /var/log/syslog
  • Type /error then press n repeatedly to walk through every match. This is far faster than re-running grep for each hit.

4. Watch a File Grow

less +F access.log
  • +F acts like tail -f: less keeps showing new lines as they’re appended. Press Ctrl+C to stop following and go back to normal scrolling (or F to resume).

5. Open at a Specific Line

less +500 file.txt
  • Starts at line 500 instead of the top. Combine with / searches for jumping straight to known content.

6. View Multiple Files at Once

less file1.txt file2.txt
  • Press :n for the next file and :p for the previous one. less remembers your position in each.

7. Useful Display Options

less -N file.txt
less -S file.txt
  • -N shows line numbers (like cat -n).
  • -S chops long lines instead of wrapping them — use with ←/→ to scroll sideways.
  • -i makes searches case-insensitive; -R shows ANSI colours in command output correctly.

Common Pitfalls

  • less seems frozen. You’re probably inside a search or a pager prompt. Press q to quit, or Ctrl+C if stuck mid-search.
  • Forgetting / vs ?. / searches down, ? searches up. Getting them backwards means scrolling the wrong way — press n/N to recover.
  • less +F isn’t tail -f exactly. It buffers and can lag on very fast-growing files; for live tails, tail -f is more direct.
  • Binary files show as gibberish. Press - followed by b inside less to see non-text characters as hex, or quit with q.

CommandDescription
catDump a whole file (or several) at once
moreThe simpler, older pager
headFirst lines of a file
tailLast lines of a file, with live follow
grepFilter lines before you read them

less Cheatsheet

CommandWhat It Does
less fileOpen a file for scrolling
command | lessPage through any long output
less +F fileFollow a growing file like tail -f
less +100 fileStart at line 100
less file1 file2Browse multiple files (:n / :p)
less -N fileShow line numbers
/word then nSearch forward, step through hits
qQuit