How to jump to a particular flag in a Unix manpage?
Become or hire the top 3% of the developers on Toptal https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Island
--
Chapters
00:00 Question
00:37 Accepted answer (Score 32)
01:09 Answer 2 (Score 16)
01:48 Answer 3 (Score 5)
02:19 Answer 4 (Score 5)
02:33 Thank you
--
Full question
https://superuser.com/questions/441654/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #unix #man
#avk47
ACCEPTED ANSWER
Score 33
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.
ANSWER 2
Score 16
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.
ANSWER 3
Score 5
Also you can open the man page on specific position from command line with
man -P 'less -p " -o"' mount
ANSWER 4
Score 5
@piccobello's answer is great, but it was eating the colors in my man pages. Instead of piping to less
(since man
already uses less
by default usually), I simply pass the modified less
command to man
:
function manswitch() { man -P "less -p \"^ +$2\"" $1 }
This retains the functionality @piccobello had in his function, but retains colors.