less
Explanation
The less command is a terminal pager program used to view the contents of a text file one screen at a time. It is faster than cat for large files because it does not need to read the entire file before starting. It also allows both forward and backward navigation.
Basic Syntax
less [OPTION]... FILE...
Common Flags and Options
| Flag | Description |
|---|---|
-N, --LINE-NUMBERS | Display a line number at the beginning of each line. |
-S, --chop-long-lines | Truncate long lines rather than wrapping them. |
-I, --IGNORE-CASE | Ignore case in searches. |
Keyboard Shortcuts in less
SpaceorPage Down: Scroll forward one screen.borPage Up: Scroll backward one screen.EnterorDown Arrow: Scroll forward one line.Up Arrow: Scroll backward one line./pattern: Search forward for a pattern.?pattern: Search backward for a pattern.n: Repeat previous search.q: Quit.
Real-world Examples
-
View a large file:
less /var/log/auth.log -
View a file with line numbers:
less -N myfile.txt -
Pipe output to less for easy viewing:
dmesg | less