173

Is there a option to search within manpages?

8128
  • 28,740
NES
  • 33,195
  • 1
    Do you mean search within all the manpages to find which one has certain content, or search within one given manpage for a certain phrase? – frabjous Jan 09 '11 at 16:32
  • 3
    @frabjous i meant within one manpage, is there also a option to search all? – NES Jan 09 '11 at 16:49
  • 3
    I added that too. By the way, you can also type man man to read all of the technical details about man-pages. – Stefano Palazzo Jan 09 '11 at 16:59
  • 1
    The man for man that I am looking at, circa 2015 (I think it's Solaris... I know this is an Ubuntu board), does not mention searching using /, or anything else that can be done inside man. It has a bunch of command-line options and that's it. – Chris Jan 08 '18 at 19:46

4 Answers4

204

Just hit /, and type your search pattern.

  • Patterns can be regular expressions, for example, you could search for the word "option" by typing:

    /[Oo]ption
    

    Or find all of the long arguments with:

    /(--)[a-Z]
    

    To cancel the search, hit Ctrl+C.

    Some useful quantification operators are:

      ?    for zero or one of the preceding expression
      *    for zero or more of the preceding expression
      +    for one or more of the preceding expression
    

    And expressions can be "grouped" with parentheses, as in (--)+ (for two or more dashes).

    [a-Z] is a sequence (others include [0-9], [a-z], and so on). Sequences can be combined, as in [a-Z0-9]. You can also invert expressions with the ^ operator, e.g. (--)[^a-Z]+ for all long arguments that start with anything other than a letter.

    Another useful operation is Union (|), as in color|colour, which finds every occurrence of either "color" or "colour" (this is sometimes called boolean OR).

    If you are searching for strings containing some of these "reserved" characters (like ?, *, +), prefix them with a \ (i.e. /\+k to search for +k).

  • To jump through the results, press N (forwards) and Shift+N (backwards).

  • There is also a way to search across all manpages:

    man -K "Hello World"
    

    The man program will open the first match, and after you close it with q, offer you to

    • view the current one (Return)
    • skip the current one (Ctrl+D)
    • or exit (Ctrl+C)
  • 3
    this depends on your pager alternative: update-alternatives --display pager. This is correct for less – shellholic Jan 09 '11 at 16:35
  • 2
    is there also an option to browse through the results with a key? i.e. as in firefox you would press F3 and the cursor jumps from one result to the next? – NES Jan 09 '11 at 16:37
  • Sorry, I forgot to mention it. Added it to the answer. – Stefano Palazzo Jan 09 '11 at 16:38
  • 1
    Another useful tip for less, instead of using [oO][pP]... for each character, use -i to toggle case sensibility. – Lekensteyn Jan 22 '11 at 14:55
  • 4
    Hmm Ctrl+C to cancel doesn't seem to work for me. Esc+U does though. – evanrmurphy Sep 04 '14 at 03:00
  • "Just hit /, and type your search pattern." I hit / on the numpad and nothing happens. – Calmarius May 15 '16 at 09:31
  • 2
    The viewer that man uses has a few vim-like key shortcuts, this is just one of them – thomasrutter Jul 04 '19 at 05:01
  • 1
    What if I'm searching for +i how do I skip special character? @StefanoPalazzo – Shayan Aug 23 '19 at 12:58
  • 1
    @Shayan you can "escape" these characters by prefixing them with a backslash; so to search for +k, you'd type /\+k, where \+ means "literally a plus sign" – Stefano Palazzo Aug 23 '19 at 14:23
  • During the search all find word highlighted in same color. Is it possible to change the color of the current selected word during search? @StefanoPalazzo – alper Jul 05 '20 at 11:54
  • Sorry to be the one to ask the stupid question, but where do I run /searchterm? E.g. if I want to search the git manual for 'remotes', I try: man git /remotes but it doesn't do anything? – stevec Jan 21 '22 at 08:08
18

Minor appendix to the excellent answer from Stefano:

man uses less when no other pager specified. So you can search either with / or with ?.

If you search with / then you search forward and you use n to find the next match and N to find previous match and if you search with ? (search backward) n will search previous match and N will search the next match.

Use man less for the details.

Also you may use man -wK word to list out all manual files with some word.

prosti
  • 1,017
8

If you are already in the man page, / search is easy to use, but I prefer to specify my search word with the man command, so it opens directly on the first occurrence of the term.

This is fairly straight forward with a pipe:

man ksh | less +/LINENO

But if you wanted to stick only to man options, it seems to be very roundabout. You have to override the default output pager (less -f) with the -P option.

man -P 'less -p LINENO' ksh
  • 1
    This is what I've been looking for! man should definitely have an option to search for a string from the command line built-in. Can man ksh | less +/LINENO be phrased in a way that doesn't mention less? – milosz.lakomy_gmail.com Jan 03 '20 at 02:41
6

GUI Methods

If you have Ubuntu Desktop version installed you can search graphically.

Gnome Help

Gnome help uses yelp program. Instead of typing man ls for the CLI man page you can type yelp man:ls and view in GUI window:

yelp man:ls.png

Once loaded you can use Control + F to search.

Browser

I open the man page on the internet and use my browsers search feature Control + F.

For example if in the terminal I type in man yad in my browser I would type linux man yad.

You sometimes need to pay attention that the internet version can sometimes have newer or older list of arguments but this has rarely happened to me.

The advantages of internet manpages goes beyond search facility and includes superior scrolling plus easier copying to clipboard.