How to jump to a particular flag in a Unix manpage?
When reading a Unix manpage in the terminal, how can I jump easily to the description of a particular flag?
For instance, I need to know the meaning of the -o
flag for mount
. I run man mount
and want to jump to the place where -o
is described. Currently, I search /-o
however that option is mentioned in several places before the section that actually describes it, so I must jump around quite a bit.
Thanks.
What I do is put a few blank spaces in front of the flag like so:
/ -o
That's not 100% reliable but you jump through a much less hoops. If you want even better success rate, try "/^ +-o"
. That would find lines starting with blanks and followed by -o. I wouldn't like to type that weird string often though.
I have defined this function in my .bashrc
function manswitch () { man $1 | less -p "^ +$2"; }
which you can use as follows
manswitch grep -r
I got it from this commandlinefu.
Note: the argument to the -p
switch of less
is a regexp telling less to look for a line starting with (^
) one or more spaces (+
) followed by the switch (second arg. so $2
), so it has the advantage of working with different formatting.