3

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.

U2EF1
  • 12,907
  • 3
  • 35
  • 37
  • This isn't a programming question, and so is off-topic for SO, but `man` itself just sends its output to your default pager; I don't believe any of them are smart enough to detect what's an option in a manpage and jump to it. – Wooble Sep 10 '12 at 17:24
  • @Wooble Is looking at documentation not related to programming? – U2EF1 Sep 10 '12 at 17:37
  • 1
    The documentation to a unix tool you're not hacking on yourself? Not really. – Wooble Sep 10 '12 at 17:38
  • @Wooble This actually came up a lot when I was hacking on gnugo, but usually comes up now when I'm working with git or bash. – U2EF1 Sep 10 '12 at 19:55

2 Answers2

3

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.

Thor
  • 45,082
  • 11
  • 119
  • 130
2

In this particular case I can do a search:

/     -l

Or even just

/ -l 

This doesn't always work immediately, though, so I'm hoping there's a better answer still.

U2EF1
  • 12,907
  • 3
  • 35
  • 37
  • Do you happen to know if there's a "find next" command for search? I've never been able to find one, which means that if a string shows up multiple times I have to retype the query repeatedly to move to the next result. – octern Sep 10 '12 at 17:45
  • @octern: If your pager is `less`, use `n` for next and `N` for previous. – Thor Sep 10 '12 at 19:05