Paging Through Files (less)
The less command lets you page through files one screen at a time. It's perfect for reading large files.
Basic Usage
less filename
Why "less"?
The name comes from the phrase "less is more" - less is an improved version of an older command called more.
Navigation in less
| Key | Action |
|---|---|
Space / f | Forward one page |
b | Back one page |
d | Forward half page |
u | Back half page |
g | Go to beginning |
G | Go to end |
q | Quit |
Searching in less
| Key | Action |
|---|---|
/pattern | Search forward |
?pattern | Search backward |
n | Next match |
N | Previous match |
Example:
- Open file with
less file.txt - Type
/errorto search for "error" - Press
nto find next occurrence
less Options
| Option | Description |
|---|---|
-N | Show line numbers |
-S | Chop long lines (no wrap) |
-i | Case-insensitive search |
-F | Quit if file fits on screen |
+G | Start at end of file |
Exercise: Page Through a File
Use less to view a log file:
less vs cat vs more
| Feature | cat | more | less |
|---|---|---|---|
| Scroll back | No | No | Yes |
| Search | No | Limited | Yes |
| Large files | Bad | OK | Best |
| Navigation | None | Forward | Both |
Useful less Commands
Line Numbers
less -N file.txt
Follow File (like tail -f)
less +F /var/log/syslog
Start at Pattern
less +/error logfile.txt
Multiple Files
less file1.txt file2.txt
# :n - next file
# :p - previous file
Viewing Piped Output
cat /var/log/*.log | less
history | less
ps aux | less
Common Patterns
View Logs
less /var/log/syslog
less -N +G /var/log/auth.log # With line numbers, at end
Read Documentation
man ls | less # Actually uses less
Key Takeaways
lessis ideal for viewing large files- Navigate with Space, b, g, G
- Search with
/pattern - Press
qto quit - Better than
catfor anything over one screen

