less
is probably one of the most used programs in the UNIX world.
It’s so ubiquitous we usually barely notice it. For clarity, I mean
this less, not this
one. Despite its ubiquity, very few people
actually take time to learn its less obvious but still very useful
features. Let’s change that!
First of all, the &
key. It prompts for a search pattern and then
acts like a filter, showing only the matching lines, not unlike
grep
. Unlike grep
though, you can change this filter without
closing less
and it’s generally very useful if you need to filter
the content as an afterthought, if you decide you really could use a
filter only after producing copious amounts of output.
Another useful thing is toggling the commandline -options in a running
less
, once again without restarting it. For example you can press
-S
to toggle wrapping the long lines or -J
to mark the lines
matching the search pattern with an asterisk. It’s worth to keep in
mind that every commandline option can be toggled this way, though
obviously some are more useful this way than the others.
Last but not least, the marks known from Vim (among the others). By
pressing m
followed by almost any other key, you can save the
current position in a text and then return to it by pressing '
followed by the same key. For instance you can save two distant
places in a file with ma
and mb
and then cross-reference them by
jumping between them with 'a
and 'b
. Considering less
is very
often used for reading lenghty manpages with lots of “See SOME OTHER
SECTION for details”, it’s a godsend.
In general, every user of UNIX-like systems should at least skim the
less
keybindings, as even in such a simple tool there is much to
learn. Press h
to display them and have a good time reading through
them! I know I had!