The less command in Linux
less displays text one screen at a time with full navigation: scroll both ways, search with /, jump to the end with G. It loads lazily, so opening a multi-gigabyte log is instant. Whenever output exceeds a screen — files, man pages, command output — less is where it should land.
How less works
On a file, less seeks: it reads only what the screen needs, jumps to the end via file size, and searches by scanning forward from where you are — which is why a 10 GB log opens instantly. On a pipe, seeking is impossible, so less buffers what has arrived; G ("go to end") on a live pipe means "wait for EOF", a surprise that has puzzled everyone once.
The full-screen behavior comes from terminal control: less switches the terminal to the alternate screen and raw key mode, draws with cursor-addressing escape sequences, and restores your scrollback on quit. -R passes through color escape sequences intact — the flag that keeps piped colored output (grep --color, git) colored inside the pager.
Syntax
less [OPTIONS] FILE | CMD | less Common options
| Option | What it does |
|---|---|
/pattern | Search forward (n next match, N previous). |
G / g | Jump to end / beginning. |
F | Follow mode — tail -f inside less; Ctrl+C returns to browsing. |
-N | Line numbers. |
-S | No wrapping: long lines scroll horizontally (→/←). |
-R | Pass through colors (for piped colored output). |
q | Quit. |
How to use less: examples
$ less /var/log/syslog Open instantly, then G for the end, /error to hunt.
$ grep -r "TODO" src/ | less Any command's output, browsable.
$ less +F app.log Start in follow mode: live log with the full navigation one Ctrl+C away.
$ less -S wide.csv Wide data without wrapping soup.
Real-world use cases for less
Reading giant logs comfortably
A 12 GB log after an incident: less opens it instantly, G jumps to the end, ?ERROR searches backwards from there, -N adds line numbers for the bug report. The whole investigation without ever loading the file.
Making any output browsable
ps aux, journalctl, diff -r — anything longer than a screen: pipe into less -R (colors intact) and navigate instead of scrolling terminal history. The pager as the universal viewport.
Pro tips and common mistakes
- Inside less: / forward search, ? backward, n/N repeat, G end, q quit — five keys cover daily use.
- less +F file starts in follow mode; Ctrl+C drops back to browsing with full navigation. Better tail -f for humans.
- -S stops wrapping wide lines (CSVs, long JSON) — sideways scrolling beats visual soup.
Frequently asked questions about less
less or cat?
cat for under a screenful, less for everything else. cat dumps; less navigates.
Why "less"?
It succeeded the older pager "more" with backwards scrolling — hence the joke: less is more.
How do I search case-insensitively?
Press -i inside less to toggle, or start with less -i. Smart default: lowercase patterns match any case.
Related commands
Print file contents, number lines, and join multiple files together.
grepFind lines matching a pattern in files or piped input — the workhorse of text search.
head & tailPrint the first or last lines of a file — including live log following with tail -f.