less Command Guide for Viewing Long Files Page by Page
less displays text one screen at a time and lets you scroll, search, and jump around without loading the whole file — the safe way to read anything long.
What is less, and Why Use It?
less is a pager: it opens a file for reading without dumping it all at once. Unlike cat, it pauses at each screen, and unlike more, it can scroll in both directions and search forwards and backwards.
The name is a recursive joke — “LESS is more than MORE” — and the tool lives up to it: it’s the standard way Linux users read files.
Why Learn less?
- Files are longer than your screen. Logs, configs, man pages —
lesshandles all of them. - You need to search while reading.
/patternjumps to matches;nsteps through them. - It doesn’t load the whole file first, so opening a multi-gigabyte log is instant.
- Everything pipes into it.
command | lessis the universal way to inspect any long output.
The single most useful habit in this wiki: put
| lessafter any command whose output might be long. You can always pressqto quit.
1. Open a File
less filename.txt
Example:
less /var/log/syslog
- The file opens at the top. Nothing is loaded beyond the first screen — perfect for huge files.
2. Navigate
While less is open:
| Key | Action |
|---|---|
Space / PageDown | One page down |
b / PageUp | One page up |
↓ / Enter | One line down |
↑ | One line up |
g | Jump to the beginning |
G | Jump to the end |
Example:
less large-file.log
- Press
Gto see the last lines instantly — the pager equivalent oftail.
3. Search
| Key | Action |
|---|---|
/word | Search forward for word |
?word | Search backward for word |
n | Repeat the search in the same direction |
N | Repeat the search in the opposite direction |
Example:
less /var/log/syslog
- Type
/errorthen pressnrepeatedly to walk through every match. This is far faster than re-runninggrepfor each hit.
4. Watch a File Grow
less +F access.log
+Facts liketail -f:lesskeeps showing new lines as they’re appended. Press Ctrl+C to stop following and go back to normal scrolling (orFto resume).
5. Open at a Specific Line
less +500 file.txt
- Starts at line 500 instead of the top. Combine with
/searches for jumping straight to known content.
6. View Multiple Files at Once
less file1.txt file2.txt
- Press
:nfor the next file and:pfor the previous one.lessremembers your position in each.
7. Useful Display Options
less -N file.txt
less -S file.txt
-Nshows line numbers (likecat -n).-Schops long lines instead of wrapping them — use with←/→to scroll sideways.-imakes searches case-insensitive;-Rshows ANSI colours in command output correctly.
Common Pitfalls
lessseems frozen. You’re probably inside a search or a pager prompt. Pressqto quit, or Ctrl+C if stuck mid-search.- Forgetting
/vs?./searches down,?searches up. Getting them backwards means scrolling the wrong way — pressn/Nto recover. less +Fisn’ttail -fexactly. It buffers and can lag on very fast-growing files; for live tails,tail -fis more direct.- Binary files show as gibberish. Press
-followed bybinsidelessto see non-text characters as hex, or quit withq.
Related Commands
| Command | Description |
|---|---|
| cat | Dump a whole file (or several) at once |
| more | The simpler, older pager |
| head | First lines of a file |
| tail | Last lines of a file, with live follow |
| grep | Filter lines before you read them |
less Cheatsheet
| Command | What It Does |
|---|---|
less file | Open a file for scrolling |
command | less | Page through any long output |
less +F file | Follow a growing file like tail -f |
less +100 file | Start at line 100 |
less file1 file2 | Browse multiple files (:n / :p) |
less -N file | Show line numbers |
/word then n | Search forward, step through hits |
q | Quit |