shell · difficulty ◆
less — page through files interactively
Read long output without flooding the terminal — then scroll back up.
$ lessWhat it does
less displays the contents of a file one screenful at a time, letting you scroll forward and backward, search, and jump around without ever dumping the whole thing into your terminal. It replaces the older more, and its name is a pun: "less" is "more, backwards". Because it pages instead of printing everything, less is the right tool for reading logs, long configs, and command output that would otherwise fly past.
Why it matters
less is the safety net for the Unix pipeline. Pipe anything too long into it — man, git log, or any command's output — and you get an interactive viewer instead of a wall of scrolling text. Unlike cat, which vomits the entire file at once, less leaves your screen intact and remembers where you left off (with -R it even handles colorized output). Once you learn its keys — space to page, / to search, q to quit — you will reach for it constantly.
Example
$ less -N /var/log/syslog 1 Aug 21 08:00:01 host systemd[1]: Starting Daily apt upgrade and clean activities
2 Aug 21 08:00:03 host kernel: [ 123.456] usb 1-1: new high-speed USB device
3 Aug 21 08:00:05 host sshd[1042]: Accepted publickey for kmail from 10.0.0.5
4 Aug 21 08:00:07 host systemd[1]: Started Daily apt upgrade and clean activities
:-N shows line numbers on the left. Use the j/k keys (or arrows) to scroll, and q to quit.
$ ps aux | lessUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 168912 13768 ? Ss 08:00 0:01 /sbin/init
root 245 0.1 0.2 1691200 23892 ? Sl 08:00 0:00 /usr/lib/systemd/systemd
kmail 1890 0.3 0.3 1054520 36552 ? Sl 08:01 0:02 /usr/bin/kitty
...
(END)Pipe any long command output into less to paginate it. Type /nginx to search forward for 'nginx', n to jump to the next match.
Common flags
- -N
- show line numbers in the left margin
- -R
- render ANSI color codes instead of showing them as junk
- -S
- chop (don't wrap) long lines; scroll sideways with arrows
- -i
- ignore case during searches
- -G
- only highlight the currently matching search term
- -F
- quit if the file fits on one screen (like cat when short)
- -X
- leave the file's content on screen after quitting
History
Origin
less was written by Mark Nudelman and first released in 1984, explicitly to be "less" — a more that lets you scroll backwards (the more utility only went forward). Because it reads only as much of the file as you view, less could open files too large for more to handle, and its search and navigation quickly made it the default pager on most Unix systems.
Fun fact
less is the default paginator behind the man pages on nearly every Linux distribution — so every time you read a manual with space, b, or / you are using less. Its name also appears everywhere in the joke category: "less is more" is the standard answer to why it replaced the more command.