Skip to content

Instantly share code, notes, and snippets.

@glnds
Last active April 19, 2024 15:15
Show Gist options
  • Star 74 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save glnds/8862214 to your computer and use it in GitHub Desktop.
Save glnds/8862214 to your computer and use it in GitHub Desktop.
Less Cheatsheet

Less Cheatsheet

less {filename}
Navigation
SPACE forward one window
b backward one window
d forward half window
u backward half window
j navigate forward by one line
10j 10 lines forward.
k navigate backward by one line
10k 10 lines backward.
G go to the end of file
g go to the start of file
q or ZZ exit the less pager
Search
/ search for a pattern which will take you to the next occurrence.
? search for a pattern which will take you to the previous occurrence.
n for next match in forward
N for previous match in backward
Other
F simulate tail -f inside less pager
ma mark the current position with the letter ‘a’,
‘a go to the marked position ‘a’.
&pattern display only the matching lines, not all.
v using the configured editor edit the current file.
CTRL+G show the current file name along with line, byte and percentage statistics.
@newlime-jacoder
Copy link

How to finish/interrupt the less command in "&pattern" mode?
Just use & again with no pattern, i.e. enter & and hit return.

as taken from https://stackoverflow.com/questions/47185850/linux-how-to-finish-interrupt-the-less-command-in-pattern-mode

@0x-2a
Copy link

0x-2a commented Apr 12, 2024

Consider adding:

# Start less and follow as new lines come in
less +F foo.log

# Render lines with colors (ignore color problems, interprets color on each new line) 
less -R foo.log

# Render lines with colors (for precise color output, continues line colors for new lines until escaped) 
less -r foo.log

# Show line numbers on start
less -N foo.log

# Combine args to start and follow, show line numbers, with color
less +F -N -R foo.log
Keys Action
ctrl c exit search, follow, filter, etc
123g goto line 123 (don't hit enter)
123 (space) goto line 123 (don't hit enter)
/ then ctrl r toggle search regex on/off
& stop displaying matching lines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment