Linux less Command
last modified October 23, 2026
The less command is a pager: it shows a file or the output of a
command one screen at a time and lets us scroll, search, and filter it.
Unlike an editor, it does not read the whole file before showing it, so it
opens multi-gigabyte logs instantly. It is the default pager for
man, git, journalctl, and
systemctl, so its keys are worth knowing even for those who
never type less themselves. The name is a pun on the older
more pager, which could only scroll forward.
The examples use less 590 in an 80-column terminal and a 200-line
application log, app.log. The screens were captured after the
keys described in each section were pressed; the terminal height varies
between examples to keep them short. In a real terminal, search matches
are highlighted.
Viewing a file
We pass the file name to less. It is left with
q.
less app.log
less fills the screen with the beginning of the file. The last
line is the prompt; on the first screen, it shows the file name, later just
a colon. Lines longer than the terminal are wrapped, as with the two long
request lines. When less exits, the screen is restored, and
the shell prompt appears where it was.
$ less app.log 2026-10-23 08:00:23 INFO user 1334 logged in 2026-10-23 08:00:29 WARN slow query on orders table took 749 ms 2026-10-23 08:01:09 WARN slow query on orders table took 77 ms 2026-10-23 08:01:17 INFO request GET /api/products 200 in 493 ms 2026-10-23 08:01:25 INFO request GET /api/products 200 in 1694 ms 2026-10-23 08:02:04 WARN slow query on orders table took 1292 ms 2026-10-23 08:02:44 INFO cache refreshed (1200 keys) 2026-10-23 08:03:12 ERROR payment failed for order A-96: card declined 2026-10-23 08:03:50 INFO request POST /api/orders 201 in 859 ms 2026-10-23 08:04:02 INFO cache refreshed (632 keys) 2026-10-23 08:04:40 INFO request GET /api/cart 200 in 212 ms 2026-10-23 08:05:20 INFO request GET /api/products?category=keyboards&sort=pric e&order=asc&page=2&limit=50&session=8f1c2a9e7d4b 200 in 41 ms 2026-10-23 08:05:29 INFO request GET /api/products?category=keyboards&sort=pric e&order=asc&page=2&limit=50&session=8f1c2a9e7d4b 200 in 41 ms 2026-10-23 08:05:35 INFO user 1394 logged in 2026-10-23 08:06:12 INFO request POST /api/orders 201 in 954 ms 2026-10-23 08:06:52 INFO request POST /api/orders 201 in 614 ms 2026-10-23 08:07:10 INFO request GET /api/cart 200 in 168 ms 2026-10-23 08:07:49 INFO user 1793 logged in 2026-10-23 08:08:13 INFO request POST /api/orders 201 in 1248 ms 2026-10-23 08:08:20 WARN retrying payment gateway (attempt 2) 2026-10-23 08:08:44 INFO user 864 logged in app.log
Moving around
less is controlled with single keys. Many of them come from
the vi editor.
| Key | Action |
|---|---|
Space, f, PgDn | Forward one screen |
b, PgUp | Back one screen |
j, Enter, Down | Forward one line |
k, Up | Back one line |
d, u | Forward, back half a screen |
g, < | Go to the first line |
G, > | Go to the last line |
Right, Left | Scroll horizontally (with -S) |
q | Quit |
We press G to jump to the end of the file.
less app.log G
The prompt shows (END) when the last line is on the screen.
Jumping to the end is the usual first step with a log file, where the
newest entries are at the bottom.
$ less app.log 2026-10-23 09:10:31 WARN slow query on orders table took 154 ms 2026-10-23 09:10:47 INFO user 1128 logged in 2026-10-23 09:11:04 INFO request POST /api/orders 201 in 1555 ms 2026-10-23 09:11:35 INFO cache refreshed (395 keys) 2026-10-23 09:11:53 WARN retrying payment gateway (attempt 2) 2026-10-23 09:12:01 INFO request POST /api/orders 201 in 530 ms 2026-10-23 09:12:40 INFO request GET /api/products 200 in 1536 ms 2026-10-23 09:13:09 INFO cache refreshed (431 keys) 2026-10-23 09:13:36 INFO request GET /api/products 200 in 1021 ms 2026-10-23 09:13:56 INFO request POST /api/orders 201 in 258 ms 2026-10-23 09:14:31 INFO request GET /api/cart 200 in 190 ms (END)
Going to a line
Most commands accept a number typed before them. A number followed by
g jumps to that line; followed by p or
%, to that percentage of the file.
less -N app.log 100g
The -N option shows line numbers, which can also be toggled
from inside less by typing -N. After typing
100g, line 100 is at the top of the screen. Similarly,
50p jumps to the middle of the file and 10j moves
ten lines forward.
$ less -N app.log
100 2026-10-23 08:37:52 INFO request GET /api/cart 200 in 331 ms
101 2026-10-23 08:38:22 INFO user 695 logged in
102 2026-10-23 08:38:51 INFO request POST /api/orders 201 in 189 ms
103 2026-10-23 08:39:17 ERROR database connection lost, reconnecting in 5 s
104 2026-10-23 08:39:21 INFO cache refreshed (1278 keys)
105 2026-10-23 08:39:42 INFO request GET /api/products 200 in 232 ms
106 2026-10-23 08:39:59 INFO request GET /api/products 200 in 173 ms
:
Searching
A slash starts a forward search, and a question mark a backward search. The pattern is a regular expression.
less app.log /ERROR n
After /ERROR and Enter, less moves the first
match to the top of the screen. The n key repeats the search
and goes to the next match, and N goes back to the previous
one. Here, the second error is at the top, and a third one follows two
lines below. In a terminal, all matches on the screen are highlighted;
Esc u turns the highlighting off.
$ less app.log 2026-10-23 08:27:09 ERROR payment failed for order A-1079: card declined 2026-10-23 08:27:20 INFO request GET /api/cart 200 in 1692 ms 2026-10-23 08:27:36 ERROR payment failed for order A-600: card declined 2026-10-23 08:28:11 INFO cache refreshed (668 keys) 2026-10-23 08:28:30 INFO request GET /api/cart 200 in 125 ms 2026-10-23 08:28:55 INFO cache refreshed (1670 keys) 2026-10-23 08:29:31 INFO cache refreshed (268 keys) 2026-10-23 08:30:08 INFO cache refreshed (39 keys) 2026-10-23 08:30:39 INFO cache refreshed (9 keys) :
Filtering lines
The & command shows only the lines that match a pattern,
like an interactive grep.
less app.log &ERROR|WARN
The pattern ERROR|WARN keeps the errors and warnings and hides
all other lines. The ampersand in the prompt reminds us that a filter is
active. Typing & with an empty pattern shows all lines
again, and &!pattern shows the lines that do not match.
Unlike grep, we can refine the filter and then navigate the
full file without leaving less.
$ less app.log 2026-10-23 08:00:29 WARN slow query on orders table took 749 ms 2026-10-23 08:01:09 WARN slow query on orders table took 77 ms 2026-10-23 08:02:04 WARN slow query on orders table took 1292 ms 2026-10-23 08:03:12 ERROR payment failed for order A-96: card declined 2026-10-23 08:08:20 WARN retrying payment gateway (attempt 2) 2026-10-23 08:10:24 WARN slow query on orders table took 1935 ms 2026-10-23 08:12:39 WARN retrying payment gateway (attempt 2) 2026-10-23 08:17:32 WARN slow query on orders table took 903 ms 2026-10-23 08:17:45 WARN slow query on orders table took 210 ms 2026-10-23 08:19:22 WARN retrying payment gateway (attempt 2) 2026-10-23 08:24:10 WARN slow query on orders table took 465 ms & :
Long lines
By default, long lines are wrapped. The -S option chops them
at the screen edge instead.
less app.log 11g less -S app.log 11g
With wrapping, each long request occupies two screen lines. With
-S, every line of the file is one screen line, marked with
> where it is cut; the arrow keys scroll horizontally to
see the rest. Chopping keeps the columns of wide output, such as CSV files
or ps aux, aligned. Typing -S inside
less toggles the option.
$ less app.log 2026-10-23 08:04:40 INFO request GET /api/cart 200 in 212 ms 2026-10-23 08:05:20 INFO request GET /api/products?category=keyboards&sort=pric e&order=asc&page=2&limit=50&session=8f1c2a9e7d4b 200 in 41 ms 2026-10-23 08:05:29 INFO request GET /api/products?category=keyboards&sort=pric e&order=asc&page=2&limit=50&session=8f1c2a9e7d4b 200 in 41 ms : $ less -S app.log 2026-10-23 08:04:40 INFO request GET /api/cart 200 in 212 ms 2026-10-23 08:05:20 INFO request GET /api/products?category=keyboards&sort=pri> 2026-10-23 08:05:29 INFO request GET /api/products?category=keyboards&sort=pri> 2026-10-23 08:05:35 INFO user 1394 logged in 2026-10-23 08:06:12 INFO request POST /api/orders 201 in 954 ms :
A more informative prompt
The -M option shows a long prompt with the position in the
file.
less -M app.log
The prompt shows the file name, the lines on the screen, the total number
of lines, and the percentage of the file above the bottom of the screen.
Without -M, the same information is displayed on request with
= or Ctrl+G.
$ less -M app.log 2026-10-23 08:00:23 INFO user 1334 logged in 2026-10-23 08:00:29 WARN slow query on orders table took 749 ms 2026-10-23 08:01:09 WARN slow query on orders table took 77 ms 2026-10-23 08:01:17 INFO request GET /api/products 200 in 493 ms 2026-10-23 08:01:25 INFO request GET /api/products 200 in 1694 ms app.log lines 1-5/200 3%
Starting at a position
An argument starting with + is a command that
less runs at startup.
less +/database app.log less +G app.log
+/database opens the file at the first match of the search,
and +G at the end. less +100 file starts at line
100. This is convenient in aliases and scripts, for example
alias lastlog='less +G /var/log/app.log'.
$ less +/database app.log 2026-10-23 08:39:17 ERROR database connection lost, reconnecting in 5 s 2026-10-23 08:39:21 INFO cache refreshed (1278 keys) 2026-10-23 08:39:42 INFO request GET /api/products 200 in 232 ms 2026-10-23 08:39:59 INFO request GET /api/products 200 in 173 ms 2026-10-23 08:40:18 INFO request GET /api/cart 200 in 554 ms app.log $ less +G app.log 2026-10-23 09:12:40 INFO request GET /api/products 200 in 1536 ms 2026-10-23 09:13:09 INFO cache refreshed (431 keys) 2026-10-23 09:13:36 INFO request GET /api/products 200 in 1021 ms 2026-10-23 09:13:56 INFO request POST /api/orders 201 in 258 ms 2026-10-23 09:14:31 INFO request GET /api/cart 200 in 190 ms app.log (END)
Reading from a pipe
Without a file name, less reads its standard input, which
makes it the end of many pipelines.
grep -n WARN app.log | less
The output of grep can be scrolled and searched like a file.
Typical uses are ps aux | less, dmesg | less, and
command 2>&1 | less to page both output streams. On a
pipe, the prompt shows no file name, and less does not know
the total size until it has read everything.
$ grep -n WARN app.log | less 2:2026-10-23 08:00:29 WARN slow query on orders table took 749 ms 3:2026-10-23 08:01:09 WARN slow query on orders table took 77 ms 6:2026-10-23 08:02:04 WARN slow query on orders table took 1292 ms 20:2026-10-23 08:08:20 WARN retrying payment gateway (attempt 2) 25:2026-10-23 08:10:24 WARN slow query on orders table took 1935 ms 30:2026-10-23 08:12:39 WARN retrying payment gateway (attempt 2) 43:2026-10-23 08:17:32 WARN slow query on orders table took 903 ms :
Following a growing file
The F command, or the +F option, makes
less wait for new data at the end of the file, like
tail -f.
less +F app.log
While less was waiting, a new error was appended to the log,
and it appeared at the bottom. The advantage over tail -f is
that Ctrl+C stops following without leaving less:
we can scroll back and search the whole file, and then press
F to resume following.
$ less +F app.log 2026-10-23 09:13:09 INFO cache refreshed (431 keys) 2026-10-23 09:13:36 INFO request GET /api/products 200 in 1021 ms 2026-10-23 09:13:56 INFO request POST /api/orders 201 in 258 ms 2026-10-23 09:14:31 INFO request GET /api/cart 200 in 190 ms 2026-10-23 09:20:01 ERROR payment failed for order A-2001: card declined Waiting for data... (interrupt to abort)
Multiple files
With several files, :n goes to the next file and
:p to the previous one.
less app.log old.log :n
After :n, less shows yesterday's log, and the
prompt tells us that it is file 2 of 2. :e file opens another
file, and a pattern starting with an asterisk, as in
/*database, searches across all the files.
$ less app.log old.log 2026-10-22 08:00:23 INFO user 1334 logged in 2026-10-22 08:00:29 WARN slow query on orders table took 749 ms 2026-10-22 08:01:09 WARN slow query on orders table took 77 ms 2026-10-22 08:01:17 INFO request GET /api/products 200 in 493 ms 2026-10-22 08:01:25 INFO request GET /api/products 200 in 1694 ms old.log (file 2 of 2)
Short output
For output that fits on one screen, the full-screen pager only gets in the
way. The -F option exits immediately in that case, and
-X leaves the text on the screen.
less -FX short.txt
The file is printed like with cat, and the shell prompt
returns at once. With longer input, less works as usual.
Git uses FRX as its default LESS setting, which is
why short git log output does not open a pager.
$ less -FX short.txt line one line two line three
Default options and case
Options in the LESS environment variable apply to every run,
including when less is started by man or
git. The case of searches is a good example.
LESS='-iM' less +/DATABASE app.log LESS='-IM' less +/DATABASE app.log
The -i option is "smart": searches ignore case only if the
pattern is all lowercase. The pattern DATABASE contains
uppercase letters, so it is case-sensitive, and nothing is found. The
-I option ignores case in all searches, and the lowercase log
message is found. A typical setting in ~/.bashrc is
export LESS='-iMR', where -R displays colours of
commands such as grep --color=always.
$ LESS='-iM' less +/DATABASE app.log Pattern not found (press RETURN) $ LESS='-IM' less +/DATABASE app.log 2026-10-23 08:39:17 ERROR database connection lost, reconnecting in 5 s 2026-10-23 08:39:21 INFO cache refreshed (1278 keys) 2026-10-23 08:39:42 INFO request GET /api/products 200 in 232 ms 2026-10-23 08:39:59 INFO request GET /api/products 200 in 173 ms 2026-10-23 08:40:18 INFO request GET /api/cart 200 in 554 ms app.log lines 103-107/201 54%
Compressed files
The zless command pages files compressed with gzip.
zless old.log.gz
The file is decompressed on the fly; the original stays compressed. Many
distributions also configure a lesspipe input preprocessor
through the LESSOPEN variable, so that plain less
can show compressed files, archive listings, and other formats.
$ zless old.log.gz 2026-10-22 08:00:23 INFO user 1334 logged in 2026-10-22 08:00:29 WARN slow query on orders table took 749 ms 2026-10-22 08:01:09 WARN slow query on orders table took 77 ms 2026-10-22 08:01:17 INFO request GET /api/products 200 in 493 ms old.log.gz
Built-in help
The h key shows a summary of all commands.
less app.log h
The help is itself displayed in less, so we scroll it with
the same keys and leave it with q, which returns us to the
file.
$ less app.log
SUMMARY OF LESS COMMANDS
Commands marked with * may be preceded by a number, N.
Notes in parentheses indicate the behavior if N is given.
A key preceded by a caret indicates the Ctrl key; thus ^K is ctrl-K.
h H Display this help.
q :q Q :Q ZZ Exit.
---------------------------------------------------------------------------
MOVING
e ^E j ^N CR * Forward one line (or N lines).
y ^Y k ^K ^P * Backward one line (or N lines).
f ^F ^V SPACE * Forward one window (or N lines).
b ^B ESC-v * Backward one window (or N lines).
z * Forward one window (and set window to N).
w * Backward one window (and set window to N).
HELP -- Press RETURN for more, or q when done
More useful commands
| Command | Action |
|---|---|
/pattern, ?pattern | Search forward, backward |
n, N | Next, previous match |
&pattern | Show only matching lines |
F | Follow the end of the file |
ma, 'a | Set mark a, return to mark a |
= | Show file information |
v | Edit the file in $VISUAL or $EDITOR |
!command | Run a shell command |
-option | Toggle an option, such as -N or -S |
:n, :p | Next, previous file |
h | Help |
Because v and ! start other programs, running
less with sudo gives a root shell to anyone who
may use it. To page a protected file, use sudo cat file |
less, or start less with the LESSSECURE=1
variable, which disables these commands.
Best practices for less
- Use less instead of an editor for viewing: It opens large files instantly and cannot modify them by accident.
- Jump and search:
G,/, and&are faster than scrolling through a log. - Prefer less +F to tail -f: You can stop, search, and resume following.
- Set defaults in LESS: For example
export LESS='-iMR'in~/.bashrc. - Use -S for wide data: Chopped lines keep tables and CSV files readable.
Source
less(1) manual page, less home page
In this article, we have used the less command to view files
and command output, move and jump around, search and filter lines, chop
long lines, follow a growing log, page several and compressed files, and
set default options. See also the
head and tail and
grep articles.
Author
List all Linux tutorials.