less
Overview
The less command is a file pager that allows forward and backward movement in a file. It’s more feature-rich than more and doesn’t need to read the entire file before starting.
Syntax
less [options] file...Common Options
| Option | Description |
|---|---|
-N |
Show line numbers |
-i |
Case-insensitive search |
-g |
Highlight only last match |
-s |
Squeeze multiple blank lines |
-F |
Quit if entire file fits on screen |
-X |
Don’t clear screen on exit |
-R |
Output “raw” control characters |
-S |
Chop long lines |
+F |
Follow mode (like tail -f) |
Key Use Cases
- View large files
- Search through files
- Monitor log files
- Read documentation
- Text navigation
Examples with Explanations
Example 1: Basic Usage
less file.txtView file with pagination
Example 2: With Line Numbers
less -N file.txtShow line numbers while viewing
Example 3: Follow Mode
less +F logfileMonitor file updates in real-time
Understanding Output
Navigation Commands: - Space/f: Forward one window - b: Backward one window - g: Go to start - G: Go to end - /pattern: Search forward - ?pattern: Search backward - n: Next match - N: Previous match - q: Quit
Common Usage Patterns
View with line numbers:
less -N fileCase-insensitive search:
less -i fileMonitor logs:
less +F /var/log/syslog
Performance Analysis
- Memory efficient
- Handles large files well
- Quick startup time
- Search optimization
- Screen buffer management
Additional Resources
Advanced Features
- Multiple file handling
- Bookmarks
- Shell command execution
- Pattern highlighting
- Line filtering
Key Bindings
| Key | Action |
|---|---|
| h | Help |
| q | Quit |
| f | Forward one window |
| b | Backward one window |
| g | First line |
| G | Last line |
| /pattern | Search forward |
| ?pattern | Search backward |
| n | Next search match |
| N | Previous search match |
| v | Edit current file |