For example instead of whole manual of apt-get
I want jump to -f
option from terminal prompt right away, without using search through manpage.
For example instead of whole manual of apt-get
I want jump to -f
option from terminal prompt right away, without using search through manpage.
Type a forward slash, the thing you are searching for, and then press enter. You will jump to the first occurrence. Press N to move to next occurrence and B to go back. So, in this case:
The default pager used by
man
isless
. You can pass the ERE (Extended Regular Expression) search pattern thatless
understands directly to it via theLESS
environment variable, in you case the following should do:This is exactly same as passing
/-f
after doingman apt-get
.Now, this would highlight all
-f
s in theman
page, to jump straight to the desired one i.e. option-f
, you can leverage ERE to match only the lines that start with spaces/tabs, followed by-f
:Although this would do here but still might not be precise for all pages, as this will match anything that starts with
-f
after initial spaces/tabs. Tweak the pattern a bit to meet you need in those cases.You can create a tiny function to pass the search pattern and the
man
page to look for as arguments, if you do this often.Use
sed
to show the entire paragraph of an option the begins with a hyphen. To show the entire paragraph of the-f
option right away by running a single command use:This returns the entire paragraph for the
-f
option in manapt-get
but the above command can be improved by eliminating the comma after-f
to make it more generally useful as follows:This returns multiple paragraphs, most of which you don't want to read. By reading the first lines of the multiple paragraphs, you can see that you want to show only the paragraph containing the
-f, --fix-broken
option. Do this as follows:This returns only the output that you want to read. This method works with any other options that begin with a hyphen, and it also works generally for searching for options that begin with a hyphen in other commands besides just
apt-get
too.Showing additional information with sed
If the one paragraph description does not give enough information, the following command will show the first paragraph the same as the previous command and the next paragraphs after it too.
The results of this command show that the next paragraphs are not very interesting, but for some options the next paragraphs are interesting too. That is why this is also a useful command to know.