Find an error in a long log
Search is case-sensitive. For case-insensitive search start with -i, or type -i
inside less.
The less pager shows a long file or command output screen by screen — scroll, search by word, follow the end.
less /var/log/syslog
open a file; q to quit
less -N app.conf
with line numbers
less -S access.log
don't wrap long lines
less +G app.log
open at the end
less +F app.log
follow the end, like tail -f
ps aux | less
page through command output
less is a pager: a program that shows text one screen at a time and waits for keys.
Unlike cat it doesn't dump everything at once, and unlike an editor it never
changes the file.
The bottom line is a status line: the file name, a colon, or (END) at the end. You
type commands right in the window, without Enter, except for searches:
| Key | What it does |
|---|---|
Space, f / b |
a screen forward / back |
↓ ↑, j / k |
a line forward / back |
g / G |
to the start / end |
/word Enter |
search forward |
?word Enter |
search backward |
n / N |
next / previous match |
&word Enter |
show only lines with the word |
F |
wait for new lines, Ctrl+C to stop |
h |
help on keys |
q |
quit |
Other commands open less too: man, journalctl and systemctl status
show long output through it. The same keys work there.
Startup options can be toggled from inside as well: type -N in an open less, and
line numbers appear. Full list — man less.
| Option | What it does | Example |
|---|---|---|
-N |
Show line numbers. | less -N app.conf |
-S |
Don't wrap long lines — scroll sideways with the arrows. | less -S access.log |
-i |
Ignore case in searches unless the pattern has capital letters. | less -i app.log |
-R |
Show colors instead of ESC[...m codes. | grep --color=always err app.log | less -R |
+F |
Open in follow mode at the end of the file, like tail -f. | less +F app.log |
+G |
Open at the last line. | less +G app.log |
-F |
Quit at once if the text fits on one screen. | less -F short.txt |
Nothing found. Try a shorter query.
Search is case-sensitive. For case-insensitive search start with -i, or type -i
inside less.
Inside less, type &Failed and Enter: only lines containing Failed stay. & and
Enter with no word bring back the whole text.
The v key opens the current file in the default editor — on Ubuntu that's usually
nano. When you leave the editor, you're back in less.
q. If text is being typed at the bottom (a command or search has started), press
Esc or Ctrl+C first, then q. To leave F mode press Ctrl+C, then q.
The word isn't below the current position. / searches forward from the screen: go
to the start (g) and repeat, or search backward with ?. Check the letter case.
The file is binary, and reading it as text makes no sense. Answer n. file name
tells what it is — see file.
The program printed color codes, and less shows them as characters. Run less -R.
less was started with no file and no pipe. Give a file (less app.log) or pipe
output into it: command | less.
Found an inaccuracy? Report an error in the article