GNU Less is a simple terminal pager program that can print, scroll and highlight text. Mark Nudelman wrote it as a robust free software alternative to the original BSD UNIX “more” program. Nowadays, less is a core part of the GNU toolset, and, as such, it comes with almost all Linux distros by default.
Download this Cheatsheet
Enter your email below to receive this PDF cheatsheet in your Inbox.
Essential GNU Less Keyboard Shortcuts
One of the biggest strengths of GNU Less is that it is simple and easy to use. Unlike other text pagers and printers, it uses almost no dependencies, and it will work even on the simple console output. You can easily save your terminal output to a file and perform virtually any desired task. Furthermore, GNU Less also comes with keyboard shortcuts that can make browsing text flexible and intuitive.
This cheat sheet will show you how to make the most of GNU Less by highlighting its most common features and keybindings. Not only that, but this cheat sheet will also show some of the pager’s advanced commands along with their shortcuts.
Shortcut | Function |
---|---|
Buffer Movement | |
J | Move the buffer one line down. |
K | Move the buffer one line up. |
F | Move the buffer one window down. |
B | Move the buffer one window up. |
D | Move the buffer by half a window down. |
U | Move the buffer by half a window up. |
Right Arrow | Move the buffer by half a window to the right. |
Left Arrow | Move the buffer by half a window to the left. |
Esc + Space | Move the buffer one window down while ignoring the file’s EOF signal. |
Shift + F | Go to the end of the file and wait for incoming data. |
Bookmarking and Navigation | |
M + Q | Create a temporary cursor bookmark and save it on the Q register. |
Quote (‘) + Q | Go to the location of the cursor bookmark on the Q register. |
Quote (‘) + Quote (‘) | Go to the location of the previous cursor bookmark. |
G | Go to the first line of the file. |
Shift + G | Go to the last line of the file. |
50 + P | Place the cursor in the middle of the file. |
Text Searching | |
Slash (/) | Open GNU Less’ search forward prompt. |
Shift + Slash (/) | Open GNU Less’ search backward prompt. |
Slash (/) + Exclamation (!) | Perform an inverse forward search. |
Shift + Slash (/) + Exclamation (!) | Perform an inverse backward search. |
N | Find the next instance of the current word query. |
Shift + N | Find the previous instance of the current word query. |
Esc + U | Toggle GNU Less’ query highlighting. |
Ampersand (&) | Find and print the lines that contain the current word query. |
Slash (/) + Asterisk (*) | Open the multi-file search forward prompt. |
Shift + Slash (/) + Asterisk (*) | Open the multi-file search backward prompt. |
Esc + N | Perform a multi-file forward search for the current word query. |
Esc, then Shift + N | Perform a multi-file backward search for the current word query. |
Slash (/) + Asperand (@) | Do a sequential multi-file forward search. |
Shift + Slash (/) + Asperand (@) | Do a sequential multi-file backward search. |
Left Square Bracket ([) | Find the matching right square bracket (]) in the current buffer. |
Right Square Bracket (]) | Find the matching left square bracket ([) in the current buffer. |
File and Interface Manipulation | |
H | Open the GNU Less help screen. |
Shift + V | Print the version number of the current GNU Less process. |
R | Refresh the entire screen. |
Shift + R | Refresh the entire screen without using GNU Less’ buffer memory. |
Shift + Semicolon (;), then E | Open a new file in GNU Less. |
Equals (=) | Print the file name of the currently loaded file. |
Shift + Semicolon (;), then N | Open the next loaded file in the current session. |
Shift + Semicolon (;), then P | Open the previously loaded file in the current session. |
Shift + Semicolon (;), then D | Remove the currently loaded file in the current session. |
Shift + Semicolon (;), then X | Open the first file in the current session. |
V | Edit the currently loaded file using the default system editor. |
Shift + Backslash (\), then Period (.) | Pipe the current screen to a shell command. |
Shift + Backslash (\), then Caret (^) | Pipe the first line of the file to a shell command. |
Shift + Backslash (\), then Dollar ($) | Pipe the last line of the file to a shell command. |
Shift + Semicolon (;), then Q | Exit the current GNU Less session. |
Command Buffer | |
Esc + L | Move the cursor one character to the right. |
Esc + H | Move the cursor one character to the left. |
Esc + 0 | Move the cursor to the beginning of the input buffer. |
Esc + Dollar ($) | Move the cursor to the end of the input buffer. |
Esc + F | Move the cursor one word to the right. |
Esc + B | Move the cursor one word to the left. |
Esc + X | Delete the character directly underneath the cursor. |
Esc + K | Print the previous command on the input buffer. |
Esc + J | Print the most recent command on the input buffer. |
Tab | Toggle the input buffer’s autocomplete feature. |
Esc + Tab | Cycle through the input buffer’s autocomplete hints. |
Ctrl + G | Delete the contents of the current input buffer. |
Ctrl + U | Cancel the command in the current input buffer. |
Image credit: Unsplash. All alterations by Ramces Red.
Our latest tutorials delivered straight to your inbox