less Command Cheatsheet
The less command is a powerful pager used to view the contents of a file one screen at a time. Unlike `cat`, it's non-destructive and highly efficient for large files because it doesn't load the entire file into memory.
Basic Usage and Options
| Command | Description |
|---|---|
less [FILE] | Opens the file for viewing. |
-S | Prevents line wrapping. Lines that are too long for the screen will be truncated, and you can scroll horizontally to see them. |
-N | Displays line numbers at the beginning of each line. |
+F | Starts `less` in "follow mode," similar to `tail -f`. It continuously displays new content as it's added to the file. Press `Ctrl-c` to exit follow mode. |
Navigation and Searching
Once you are inside `less`, you can use these keys to navigate and search.
| Key | Action |
|---|---|
Spacebar or f | Scrolls forward one screen. |
b | Scrolls backward one screen. |
g | Goes to the beginning of the file. |
G | Goes to the end of the file. |
/pattern | **Searches forward for a regular expression pattern.** |
?pattern | Searches backward for a regular expression pattern. |
n | Moves to the next match of the search pattern. |
N | Moves to the previous match of the search pattern. |
q | Quits `less`. |