The less command is an interactive pager for viewing text one screen at a time.
It is ideal for reading large files, log output, and command pipelines without loading content into an editor.
Overview
Use less when you need to:
- View large files without opening an editor
- Scroll through logs and command output interactively
- Search for patterns inside a file
- Follow growing files (similar to live log tailing)
- Navigate quickly by lines, percentages, and matches
Syntax
less [options] [file...]
Common forms:
# View a file
less /var/log/syslog
# View command output
journalctl -u nginx | less
# Open at first match
less +/ERROR app.log
# Follow mode (live updates)
less +F app.log
If no file is supplied, less reads from standard input.
Common Options
| Option | Purpose | Example |
|---|---|---|
-N |
Show line numbers | less -N app.log |
-S |
Chop long lines (no wrap) | less -S data.tsv |
-R |
Display raw ANSI color escapes | less -R build.log |
-X |
Do not clear screen on exit | less -X notes.txt |
-F |
Quit if content fits one screen | less -F README.md |
-i |
Case-insensitive search unless uppercase in pattern | less -i app.log |
-I |
Always case-insensitive search | less -I app.log |
+N |
Start at line N | less +120 app.log |
+/PATTERN |
Start at first PATTERN match | less +/timeout app.log |
Essential Navigation Keys
| Key | Action |
|---|---|
Space |
Next page |
b |
Previous page |
Enter |
Next line |
k / y |
Previous line |
g |
Go to first line |
G |
Go to last line |
N g |
Go to line N (example: 250g) |
N% |
Go to percentage in file (example: 50%) |
q |
Quit |
Search and Match Navigation
/patternsearch forward?patternsearch backwardnjump to next matchNjump to previous match
Examples while inside less:
/ERROR/connection timeout?Exception
Following Live Output
Use follow mode to watch files that are growing:
less +F /var/log/syslog
In follow mode:
- Press
Ctrl+Cto pause following and return to normal navigation - Press
Fto resume following
This is similar to tail -f but allows full interactive navigation when paused.
Examples
# Browse a large log with line numbers
less -N /var/log/nginx/access.log
# Preserve color output from grep
grep --color=always -n "ERROR" app.log | less -R
# View wide output without wrapping
ps aux | less -S
# Open directly at end of file
less +G app.log
# Open multiple files and move between them (:n and :p inside less)
less app.log app.log.1 app.log.2
# View compressed logs using zless wrapper
zless app.log.gz
Useful In-Session Commands
hopen built-in help:ngo to next file in argument list:pgo to previous file in argument list=show current file position
Safe Usage Guidelines
- Use
lessinstead ofcatfor large files to avoid terminal flooding. - Use
-Rwhen paging colorized output from other tools. - Use
-Sfor wide tabular output to prevent wrapped, hard-to-read lines. - Prefer
less +/patternfor quicker incident triage in large logs.
Performance Tips
lessstreams data and is efficient for very large files.- Piping into
lesskeeps interactive control while avoiding huge terminal output. - Disable line wrapping (
-S) for large structured rows to improve readability.
Troubleshooting
Colors disappear when piping output into less
Cause: Color escapes are stripped or not rendered.
Fix:
grep --color=always "error" app.log | less -R
Long lines wrap and become hard to read
Cause: Default line wrapping.
Fix:
less -S wide-output.txt
File keeps updating and view jumps
Cause: Follow mode enabled.
Fix:
- Press
Ctrl+Cto pause follow mode - Use normal navigation commands, then press
Fto resume
Notes
less is often configured as the default pager through the PAGER environment variable.
For command details and implementation-specific behavior, run:
man less
less --help