114

Is there a option to search within manpages?

  • 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 9 '11 at 16:32
  • 2
    @frabjous i meant within one manpage, is there also a option to search all? – NES Jan 9 '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 9 '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 8 '18 at 19:46
136

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), they 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 next one (Return)
    • skip the current one (Ctrl+D)
    • or exit (Ctrl+C).
  • 2
    this depends on your pager alternative: update-alternatives --display pager. This is correct for less – shellholic Jan 9 '11 at 16:35
  • 1
    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 9 '11 at 16:37
  • 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
  • 3
    Hmm Ctrl+C to cancel doesn't seem to work for me. Esc+U does though. – evanrmurphy Sep 4 '14 at 3:00
  • 1
    The viewer that man uses has a few vim-like key shortcuts, this is just one of them – thomasrutter Jul 4 at 5:01
7

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.

0

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
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.