Here’s a cheat sheet for working with the less
command in Unix/Linux terminals:
Basic Navigation
- Scrolling:
- Scroll Up:
k
or Up Arrow - Scroll Down:
j
or Down Arrow
- Scroll Up:
- Page Navigation:
- Next Page:
Spacebar
- Previous Page:
b
- Next Page:
- Line Navigation:
- Next Line:
j
or Enter - Previous Line:
k
- Next Line:
- Jump to the Top or Bottom:
- Go to Top:
g
- Go to Bottom:
G
- Go to Top:
Searching
- Search Forward:
/
followed by the search term and Enter
- Search Backward:
?
followed by the search term and Enter
- Repeat Search:
- Press
n
to repeat the search in the same direction. - Press
N
to repeat the search in the opposite direction.
- Press
Exiting
- Quit
less
:- Press
q
- Press
File Information
- Display File Name:
- Press
Ctrl
+g
- Press
- Display Line Numbers:
- Press
=
(equals sign)
- Press
Marking and Returning
- Marking a Position:
- Press
m
followed by a letter (e.g.,ma
)
- Press
- Returning to a Marked Position:
- Press
'
followed by the letter used for marking (e.g.,'a
)
- Press
Other Options
- Toggle Line Wrapping:
- Press
-
(minus sign)
- Press
- Show Line Numbers:
- Press
:
followed byset nu
and Enter - To hide line numbers, use
:
followed byset nonu
and Enter
- Press
- View Multiple Files:
less file1 file2
- Use
:n
and:p
to navigate between multiple files.
- View Binary Files:
- Use
less -f
to view binary files.
- Use
Help
- Accessing Help:
- Press
h
for help withinless
- Press
Customizing less
- Configuring Environment Variable:
export LESS="-i -M -R -F -X"
-i
: Ignore case in searches-M
: More verbose status line-R
: Preserve color escape codes-F
: Quit if the content fits on one screen-X
: Don’t clear the screen on exit
This cheat sheet covers some of the basic and commonly used commands with the less
command in Unix/Linux. Adjust and expand based on your specific needs and preferences.