less — Browse Files in the Terminal with the Pager

Practical guide to less — page through, search and live-follow files and logs in the terminal with the standard Unix pager.

less is the standard pager on Unix and Linux: it shows file contents one screen at a time without loading the whole file into memory, and lets you scroll forward and backward, search and filter. Unlike cat, less loads on demand – ideal for huge log files, long output or reading over a pipe. It is also the default pager for man pages and git diff, so you meet it constantly even without invoking it directly. Because less only reads and never modifies anything, it is harmless; this guide walks you through the key bindings and options that let you move around quickly and precisely.

Opening Files

less <file> — Open a file for browsing.

less /var/log/syslog

less <file1> <file2> — Open multiple files. Navigate between them with :n and :p.

less error.log access.log

<command> | less — Pipe command output into less for browsing.

journalctl | less

less -N <file> — Show line numbers in the left margin.

less -N script.py

less -S <file> — Chop long lines instead of wrapping. Scroll horizontally with arrow keys.

less -S wide-table.csv

less -R <file> — Show ANSI color codes (raw control characters). Essential for colored output.

git diff --color=always | less -R

less +F <file> — Open in follow mode (like tail -f). Press Ctrl+C to stop, Shift+F to resume.

less +F /var/log/syslog

less +G <file> — Open and immediately jump to the end of the file.

less +G /var/log/app.log

Space / f — Scroll forward one screen (page down).

Space or f

b — Scroll backward one screen (page up).

b

d — Scroll forward half a screen.

d

u — Scroll backward half a screen.

u

j / Down / Enter — Scroll forward one line.

j or Enter

k / Up — Scroll backward one line.

k or Up arrow

g — Jump to the beginning of the file.

g

G — Jump to the end of the file.

G

<number>g — Jump to a specific line number.

100g  (jump to line 100)

<number>% — Jump to a percentage position in the file.

50%  (jump to the middle)

Right / Left — Scroll horizontally when long lines are chopped (-S mode).

Right or Left arrow

Searching

/<pattern> — Search forward for a pattern (regex supported).

/ERROR

?<pattern> — Search backward for a pattern.

?WARNING

n — Jump to the next search match.

n

N — Jump to the previous search match.

N

&<pattern> — Show only lines matching a pattern (like grep within less).

&ERROR

&!<pattern> — Show only lines NOT matching a pattern (inverse filter).

&!DEBUG

& — Clear the filter and show all lines again.

& (then Enter)

/<pattern> with -i — Case-insensitive search. Toggle with -i while inside less.

-i then /error

Esc-u — Toggle search highlight on/off.

Esc then u

Marks & Bookmarks

m<letter> — Set a mark (bookmark) at the current position. Use any lowercase letter.

ma  (set mark 'a')

'<letter> — Jump to a previously set mark.

'a  (jump to mark 'a')

'' — Jump back to the previous position (before the last jump).

''

Multiple Files

:n — Open the next file when viewing multiple files.

:n

:p — Open the previous file.

:p

:e <file> — Open a new file without leaving less.

:e /var/log/error.log

:x — Show the list of currently opened files.

:x

Display Options (Toggle at Runtime)

-N — Toggle line numbers on/off while viewing.

-N (then Enter)

-S — Toggle line wrapping/chopping while viewing.

-S (then Enter)

-i — Toggle case-insensitive search.

-i (then Enter)

-I — Toggle case-insensitive search and pattern matching.

-I (then Enter)

-w — Toggle highlighting of the first new line after a forward scroll.

-w (then Enter)

= — Show file information: filename, line numbers, byte position, percentage.

=

v — Open the current file in the default editor ($VISUAL or $EDITOR).

v

Follow Mode

F — Enter follow mode (like tail -f). Waits for new data appended to the file.

F (while viewing a log file)

Ctrl+C — Exit follow mode and return to normal navigation.

Ctrl+C (while in follow mode)

less +F <file> — Open directly in follow mode from the command line.

less +F /var/log/syslog

Startup Options

less -N <file> — Show line numbers from the start.

less -N config.py

less -S <file> — Chop long lines from the start (no wrapping).

less -S data.csv

less -R <file> — Interpret ANSI color escape sequences.

git log --color=always | less -R

less -X <file> — Don't clear the screen when exiting. Output remains visible in terminal.

less -X notes.txt

less -F <file> — Quit immediately if the entire file fits on one screen.

less -F short-file.txt

less -RFXN <file> — Common combination: color support, auto-quit for short files, keep output, line numbers.

less -RFXN script.py

less -p '<pattern>' <file> — Open the file and jump to the first occurrence of a pattern.

less -p 'function main' app.py

less +/<pattern> <file> — Alternative syntax to open with a search pattern.

less +/ERROR /var/log/syslog

Environment & Configuration

export LESS='-RFX' — Set default less options via the LESS environment variable.

export LESS='-RFX'  # in ~/.bashrc

export LESSOPEN='| highlight -O ansi %s' — Configure an input preprocessor for syntax highlighting.

export LESSOPEN='| highlight -O ansi %s 2>/dev/null'

export PAGER=less — Set less as the default pager for man, git, and other tools.

export PAGER=less  # in ~/.bashrc

Exiting & Help

q — Quit less.

q

Q — Quit less immediately (same as q, but guaranteed even in follow mode).

Q

h — Show the built-in help screen with all key bindings.

h

Conclusion

less is the go-to tool for reading files and long output without changing them: you scroll forward and backward, jump to specific lines, search with regular expressions and filter the display – all memory-friendly, because less only loads on demand. Especially handy for logs is follow mode +F (like tail -f), which you pause with Ctrl+C and resume with Shift+F. For everyday use it is worth setting less -RFX as the default (for example via the LESS environment variable) so that colours render correctly and short files don't needlessly page away the output. Press q to leave the pager, and h to bring up the full key reference at any time.

Further Reading

  • vim – the editor you switch to from less by pressing v
  • nano – simple editor for editing the file you are reading
  • tail – shows the end of files and follows logs with -f