Command Line – Get Paragraph for Certain Option of Command

command linedocumentationmanpage

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.

Best Answer

The default pager used by man is less. You can pass the ERE (Extended Regular Expression) search pattern that less understands directly to it via the LESS environment variable, in you case the following should do:

LESS='+/-f' man apt-get

This is exactly same as passing /-f after doing man apt-get.

Now, this would highlight all -fs in the man 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:

LESS='+/^[[:blank:]]+-f' man apt-get

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.