The man
command brings up a nice manual for many programs, but how can I use it more effectively? For example man gcc
brings:
NAME
gcc - GNU project C and C++ compiler
SYNOPSIS
gcc [-c|-S|-E] [-std=standard]
[-g] [-pg] [-Olevel]
[-Wwarn...] [-Wpedantic]
[-Idir...] [-Ldir...]
[-Dmacro[=defn]...] [-Umacro]
[-foption...] [-mmachine-option...]
[-o outfile] [@file] infile...
Only the most useful options are listed here; see below for the
remainder. g++ accepts mostly the same options as gcc.
....
many text
But what if I need only some part of it? What is the best way to jump to the section where -Idir
is described, for example?
Search the
man
page by pressing / and the search stringman
is using the viewerless
by default. You can search inless
by pressing / (slash), and then add the search string, in your example-Idir
Press the Enter key, and get the first match.
Press / (slash) and the Enter key again, repeat until you find the section, that you want. You can also press n for the next match.
Pressing h gives a nice overview over the available commands.
You find more details about 'help tools' at the following link
How can I get help on terminal commands?
I can't improve on Wildcard's answer when I asked the same question at Unix & Linux Q&A.
I would like to answer it in simplest way.
Once you open manpage for the package using
man <package>
, you can use search utility to find the details of a particular options using/<option>
, example, to check the details of -r option, use/-r
.man
pages uses thevim
keybindings, so knowing the search keybindings forvim
can be very useful. And similarly,info
uses theemacs
keybindings.When you view manual pages and search by pressing /,
less
is actually treating your search pattern as a regular expression. When searching for command-line options, I find it very useful to append\b
to them, which matches a word boundary. This often skips over lots of text that would otherwise match but is not what I am looking for (or which is, in any case, not what I want to read first).For example, to search for the
-I
option, you can type:/
character tellsless
you want to search, as others have mentioned (see MIB's answer). You would write?
instead of/
if you wanted your search to go upward in the manpage instead of downward.-I
is the literal text that you are searching for.\b
matches the boundary between a word character (A-Z
,a-z
, or_
) and a non-word character, or between a word character and the very beginning or end of the text in which it occurs.You may still need to find subsequent matches. To do that, press n. To go back to preceding matches, press Shift+n.
In the case of searching for
-I
in thegcc
manpage, for example, I found that-I
was matched six times prior to the match I was looking for where the-I
option was actually documented. In contrast,-I\b
was matched just once prior to that match.If you prefer, you can use
\>
instead of\b
.\>
matches just the end of a word (where a "word" is one or more word characters as defined above). If you wanted to match the beginning of a word, you could use\<
. Note, however, that it doesn't work to write something like\<-I
to match the option-I
, because\<
would fail to match whitespace followed by-
.