less
Page through text interactively, one screen at a time
By CMD Script Team · 4 min read · Last updated
less [OPTIONS] [FILE...]Options
| Flag | Description |
|---|---|
-N | Show line numbers in the left margin |
-S | Chop long lines instead of wrapping them (enables horizontal scrolling) |
-i | Ignore case in searches unless the pattern contains uppercase letters |
-F | Exit immediately if the entire file fits on one screen |
-X | Leave file contents on screen after less exits, instead of clearing it |
+F | Start in follow mode, similar to tail -f, showing new lines as they're appended |
Distribution compatibility
- Ubuntu
- Debian
- Fedora
- Arch
- macOS
What it does
less is a terminal pager: it displays a file (or piped input) one screen at a time and
lets you navigate forward and backward, search for text, and jump around without loading
the entire file into memory first. That last property makes it practical for huge files
and live log-watching, where tools like cat are too blunt and more is too limited.
Beginner examples
less file.txt— open a file for interactive viewing- Press
SpaceorPgDnto move forward a screen - Press
borPgUpto move backward a screen - Press
qto quit ps aux | less— page through the output of another command
less /etc/passwd
Advanced examples
- Search forward for a pattern and cycle through matches:
/errorthennfor next,Nfor previous - Jump straight to the end of the file: press
G; jump back to the start withg - Follow a log file live, like
tail -f, then stop following withCtrl+C:less +F app.log - Show line numbers and disable line wrapping for wide files:
less -N -S data.csv - Case-insensitive search regardless of the pattern's case:
less -ithen search
less +F /var/log/nginx/access.log
Common mistakes
- Assuming
lessneeds to load the whole file before showing anything — it doesn't, which is exactly why it's suited to huge files and live logs, unlikecat. - Forgetting
qquitslessand instead trying toCtrl+Cout of a large file view, which can behave unexpectedly if follow mode (F) is active. - Confusing
less's backward search (?) with forward search (/) and wondering why matches appear "in the wrong direction." - Not realizing search is case-sensitive by default; add
-ior toggle with-iinside less if you need case-insensitive matches.
Tips
- Type a number before
G(e.g.50G) to jump directly to a specific line. - Use
&patterninsidelessto display only lines matching a pattern, similar to filtering withgrep. lessrespects your terminal's color codes, so piping colorized tool output (with--color=alwaystype flags) throughless -Rpreserves the colors.
Best practices
- Prefer
lessovermorefor any interactive file viewing — it's strictly more capable and available on virtually every modern Linux and macOS system. - Use
less +Finstead of repeatedly runningtailwhen actively debugging a live log, since you can drop out of follow mode to search history and resume without losing your place. - For scripts and non-interactive contexts, don't rely on
less— it's built for interactive use; usecat,head, orsedinstead when output needs to be captured or processed.
Try it yourself
A simulated shell with a sample home directory — experiment freely, nothing leaves your browser. Type help to list supported commands.
Real-world use cases
- Reviewing a multi-thousand-line application log without editing or loading it fully into an editor.
- Watching a server's access log in real time while reproducing a bug, using
less +F. - Searching a large configuration file for a specific setting with
/before deciding whether to edit it.
Common interview questions
- What's the difference between
lessandmore?lesscan scroll both forward and backward and supports live search without reading the whole file up front;moreis generally forward-only and simpler. - How would you watch a log file update in real time using less?
less +F file.logenters follow mode, similar totail -f; pressCtrl+Cto stop following. - Why is
lesspreferred overcatfor large files?lessdoesn't need to load the entire file into memory before displaying it and lets you navigate interactively, whereascatdumps the whole file to the terminal at once.
Frequently Asked Questions
How do I search inside a file while using less?
Press / followed by a pattern and Enter to search forward, or ? to search backward. Press n to jump to the next match and N for the previous one.
How do I quit less?
Press q. If you started less on multiple files, q moves to the next file unless you use -X or press capital Q / ZZ to quit entirely, depending on configuration.
What's the actual difference between less and more?
less can scroll backward (press b or use arrow keys/PgUp) and doesn't need to read the whole file before displaying it, while more can typically only page forward. less also supports live search and doesn't load the entire file into memory up front.
Can less follow a growing file like tail -f?
Yes. Run less +F file.log, or press Shift+F while already inside less, to enter follow mode. Press Ctrl+C to stop following and return to normal browsing.
Cheat sheet
Download a quick-reference cheat sheet for less.