It’s a more powerful version or “more”. It doesn’t load the entire file into memory, loads each page at a time.
The less command can also be used with output piped through another command.
ps -ef | less
The above command will show a list of running processes one page at a time.
G – go to the end of file
u – up half page
d – down half page
k – scroll single line up
j – scroll single line down
-i – case insensitive searching unless pattern contains capitals (as clo or in less)
/ /pattern/ – search (used with n)
-p /pattern/ open file at /pattern/ (as clo)
& /pattern/ show lines containing /pattern/ (like grep)
/ – search forward
? – search backwards
F – enable tail -f like behvaiour, Ctrl-C to break out of it
v – open file in $EDITOR for editing, defaults to vi/vim
-N – show line numbers
10f – scroll by 10 lines
10z – make scroll 10 lines if space/f is pressed default
e/j – scroll one line
5j – scroll 5 lines if e/j is pressed
q/Q – exit less
m followed by any lowercase letter – create marker
“lowercase letter marker” – jump to marker
You can use a lowercase “r” to repaint the screen or an uppercase “R” to repaint the screen discarding any output that has been buffered.
You can press an uppercase “F” to scroll forward. The benefit of using the “F” is that when the end of the file is reached it will keep trying. If a log is updating whilst you are using the less command any new entries will be displayed.
To go to a specific line enter a number before pressing the “g” or “G” keys.
You can move to a position which is a certain percentage through a file. Enter a number followed by the “p” or “%” key. You can even enter decimal points because let’s face it, we all need to go to position “36.6%” through a file.