How can I search within a manpage?

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).

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.


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

Tags:

Search

Manpage