Linux command list

less command: page through a long file

__ __ _ _____
\ \ / /__| |_|_ _|__ _ __ _ __ ___
\ \ /\ / / _ \ '_ \| |/ _ \ '__| '_ ` _ \
\ V V / __/ |_) | | __/ | | | | | |
\_/\_/ \___|_.__/|_|\___|_| |_| |_| |_
 
A sandbox for trying less. Nothing here can touch your real files.
user@webterm:~/project$
 

less shows a long file one screen at a time. Learn the movement keys, searching with /, and how to get out with q, by running the commands in a real terminal in your browser.

Updated: 2026-09-05

Syntax

less [options] file

Shows a file one screen at a time. It is a read-only view, so the file itself is untouched.

Try it first

The terminal on this page has a log file with 120 lines in it.

$ wc -l logs/app.log
120 logs/app.log

That is far more than one screen, so cat would scroll it all past you. Open it with less instead.

$ less logs/app.log

The screen switches to the first page of the file. The bottom line shows which file you are looking at.

001 ERROR request failed
002 INFO  request handled
003 INFO  request handled
...
logs/app.log

Press q when you are done and you return to the prompt.

Moving around

There are not many keys to learn.

KeyWhat it does
Space / fForward one screen
bBack one screen
j / Down / EnterDown one line
k / UpUp one line
d / uHalf a screen down / up
g / GJump to the top / bottom
qQuit

G is the one you use most with logs. Whatever was written last is what is happening now.

Searching inside it

Type / followed by the text and press Enter.

  • /ERROR jumps to the next line containing ERROR
  • n goes to the next match
  • N goes back to the previous one

For a long log, counting with grep first and then reading the surroundings in less is an easy rhythm.

$ grep -c ERROR logs/app.log
8

When you actually reach for it

less is where you go to read long output without rushing.

SituationWhat you type
Read a long logless app.log
A listing scrolls off the screenls -l | less
Read with line numbersless -N app.log
Read a manual pageman ls (it opens in less)

Things that trip people up

q gets you out. This is the single thing that catches people the first time. It is a read-only view, so quitting changes nothing about the file.

Short files do not need it.

$ cat notes.txt
buy milk
call the bank

If it fits on screen, cat is quicker and leaves the text in your scrollback.

It is not an editor. less only reads. Use an editor such as vim when you need to change something.

Practise it hands-on

webterm.appthis site

  • Advanced Terminal Commands

    Learn commands for specific situations

    Try the tutorial

learn.webterm.appa separate site

>_WEBTERM LEARN

WebTerm Learn: from one command to actually using it

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.

See the course

Related commands

cat / head / tail / grep

Frequently asked questions

How do I get out of less?
Press q and you are back at the prompt. less is a read-only view, so nothing happens to the file.
When should I use less and when cat?
cat for files that fit on screen, less for anything longer. cat prints everything and exits, less opens a screen you can move around in.
Can I search inside less?
Yes. Type / followed by the text and press Enter. n jumps to the next match, N to the previous one.
Why is it called less and not more?
The older pager, more, could not scroll backwards. less can, so it replaced it. The name is a joke on its predecessor.
Can I page through another command's output?
Pipe it in. ls -l | less lets you read a long listing without it scrolling away.