less command in Linux: page through a file
Updated November 1, 2026
The less command shows a file a page at a time, without reading the whole file into memory.
Syntax
less fileCommon cases
less /var/log/syslog # page through a file
journalctl | less # take input from a pipeline
# inside less:
# space / b - page forward / back
# /pattern - search, n for the next match
# q - quitSample output
$ less app.log
2026-07-19 09:12:04 INFO server started on port 8080
2026-07-19 09:12:04 INFO connected to database
2026-07-19 09:14:31 DEBUG cache miss for key user:41
2026-07-19 09:14:31 INFO GET /api/users 200 14ms
2026-07-19 09:15:02 WARN slow query 1.4s on table orders
2026-07-19 09:15:48 DEBUG cache miss for key user:87
2026-07-19 09:16:10 ERROR connection refused to redis:6379
2026-07-19 09:16:11 INFO retrying redis in 5s
2026-07-19 09:16:16 ERROR connection refused to redis:6379
app.logHow it works: why less, not cat
caton a large file pushes the start off the screen, which you cannot get back.lessreads the file lazily as you scroll, so it opens even gigabyte logs instantly and uses little memory. The name is a pun on the older pagermore:lessscrolls both ways and searches, whilemoreonly went forward. On quitlessleaves no file on the screen.
Common mistakes
The bottom line of the screen is not part of the file, it is the status line. On open it holds the file name, at the end of the file it turns into (END), and less writes its answers there too. Start it as less -M and the line gets detailed: app.log lines 1-9/15 61% shows which lines are on screen and how many there are in total.
A /pattern search runs forward from the current position, not over the whole file. Jump to the end with G, type /server, and less answers Pattern not found (press RETURN) even though the word is in the file, just above the cursor. ?pattern searches backwards, and g takes you back to the top.
grep --color=always ERROR app.log | less shows junk instead of highlighting: 2026-07-19 09:16:10 ESC[01;31mESC[KERROR connection refused. less prints control sequences as plain text until you allow them with the -R flag.
Used in
You need this in the lesson Reading text. The theory is the chapter Reading and editing text.
See also
cat, head, tail, The file command.
Try it
Open the sandbox: a real throwaway Linux terminal in your browser. Run the commands above by hand - the container is deleted when you leave.