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/syslogless <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 | lessless -N <file> — Show line numbers in the left margin.
less -N script.pyless -S <file> — Chop long lines instead of wrapping. Scroll horizontally with arrow keys.
less -S wide-table.csvless -R <file> — Show ANSI color codes (raw control characters). Essential for colored output.
git diff --color=always | less -Rless +F <file> — Open in follow mode (like tail -f). Press Ctrl+C to stop, Shift+F to resume.
less +F /var/log/syslogless +G <file> — Open and immediately jump to the end of the file.
less +G /var/log/app.logNavigation
Space / f — Scroll forward one screen (page down).
Space or fb — Scroll backward one screen (page up).
bd — Scroll forward half a screen.
du — Scroll backward half a screen.
uj / Down / Enter — Scroll forward one line.
j or Enterk / Up — Scroll backward one line.
k or Up arrowg — Jump to the beginning of the file.
gG — 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 arrowSearching
/<pattern> — Search forward for a pattern (regex supported).
/ERROR?<pattern> — Search backward for a pattern.
?WARNINGn — Jump to the next search match.
nN — 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 /errorEsc-u — Toggle search highlight on/off.
Esc then uMarks & 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.
:xDisplay 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).
vFollow 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/syslogStartup Options
less -N <file> — Show line numbers from the start.
less -N config.pyless -S <file> — Chop long lines from the start (no wrapping).
less -S data.csvless -R <file> — Interpret ANSI color escape sequences.
git log --color=always | less -Rless -X <file> — Don't clear the screen when exiting. Output remains visible in terminal.
less -X notes.txtless -F <file> — Quit immediately if the entire file fits on one screen.
less -F short-file.txtless -RFXN <file> — Common combination: color support, auto-quit for short files, keep output, line numbers.
less -RFXN script.pyless -p '<pattern>' <file> — Open the file and jump to the first occurrence of a pattern.
less -p 'function main' app.pyless +/<pattern> <file> — Alternative syntax to open with a search pattern.
less +/ERROR /var/log/syslogEnvironment & Configuration
export LESS='-RFX' — Set default less options via the LESS environment variable.
export LESS='-RFX' # in ~/.bashrcexport 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 ~/.bashrcExiting & Help
q — Quit less.
qQ — Quit less immediately (same as q, but guaranteed even in follow mode).
Qh — 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
- less(1) manual page – the complete official reference for all options and key bindings
- GNU less home page – the project home page with downloads and release notes