Search code examples
shellmanpage

How do I go directly to a particular (short) option on a manpage


Often I will open up the manpage for a command already knowing the option I am searching for and read its description. Sometimes simply searching for the option works immediately, sometimes the option is referenced elsewhere, sometimes the option just appears as a substring in the preceding text.

As a concrete example, on my computer, right now, this is the sequence of commands to get to the -l option of ls:

man ls
/-l
nnnnnnn

In this particular case there is only one group of options and they are alphabetically sorted, so I could just scroll down and find the option, or do as above. In other cases not so much. Regardless, I would like to go directly to the line.


Solution

  • If your pager is less, which it often is, it supports regular expression search. For your example this works:

    man ls
    /^ *-l\b
    

    Which anchors the match to lines starting with arbitrary whitespace followed by -l and a word-boundary \b.