Tricks and tips for finding information in man pages [closed]
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
25 Answers 25
Type slash / and then type the string to search for. Then press n to get to the next item, and press N to go to a previous one.
Pay attention to the section number: Suppose you want help on printf . there are at least two of them: in shell and in C. The bash version of printf is in section 1, the C version is in section 3 or 3C. If you don’t know which one you want, type man -a printf , and all manual pages will be displayed.
If what you are looking for is the format of printf with all % codes and it doesn’t appear on printf man page, you can jump to related man pages listed under SEE ALSO paragraph. You may find something like formats(5) , which suggests you to type man 5 formats .
If you are annoyed that man printf gives you printf(1) and all you want is printf(3), you have to change the order of scanned directories in the MANPATH environment variable and put the ones for C language before the ones for shell commands. This may happen also when Fortran or TCL/Tk man pages are listed before C ones.
If you don’t know where to start, type man intro , or man -s intro . This gives you a summary of commands of requested section.
Sections are well defined:
- 1 is for shell commands,
- 2 is for system calls,
- 3 is for programming interfaces (sometimes 3C for C, 3F for Fortran. )
- 5 is for file formats and other rules such as printf or regex formats.
Last but not least: information delivered in man pages is not redundant, so read carefully from beginning to end for increasing your chances to find what you need.
It would be cool if there was a program to search a pages by a «keywords». I.e. I recently couldn’t remember the name of the c function to find a substring (the strstr() ), and I had no an internet around me.
This will give you a list of all man pages which relate to ‘search’.
And to list all man pages which relate to ‘search’ in specific section (number 3, for instance) one could use this: man -k search -s 3 Also mentioned in superuser.com/a/677969/599957
As @Steven D says, don’t forget the info pages.
In addition, don’t be intimidated by the info pages. I know plenty of people who don’t use the info pages because of the built-in navigation system. My favorite solution is to pipe the info pages through less :
This way, I can navigate the info pages using my favorite pager. The info pages will now behave the same as man pages.
The default pager for reading a man page is less . There is documentation on less here.
- Scroll up/down by one page: b / space
- Scroll up/down by half a page: u / d
- Searching forwards/backwards: / / ? , then type a regular expression,
- then then hit n to go to the next match or
- shift + N to go to the previous match.
- If the page is covered with uninteresting matches, hit space to go to the next page.
Scroll up/down by one page can also be done with ctrl+space / f , which might be helpful depending on which fingers your prefer to use for navigation.
The apropos utility is seriously handy for finding the appropriate manpage.
‘man man’ says that ‘man -k’ is equivalent to ‘apropos -r’. I think apropos is a little more powerful. I generally use ‘man -k’ as it’s slightly shorter.
Always check out what’s in the SEE ALSO section. The commands shown under this section in info page are selectable by placing the cursor on the desired command and then pressing enter key. Frequently I find other useful commands or functions that way.
If you’re more comfortable with your editor than you are with the default pager, you can set MANPAGER in your environment. For example, I have this line in my ~/.bashrc :
export MANPAGER="col -b | vim -c 'set ft=man nomod nolist ignorecase' -"
I suppose, using most pager is a good idea. This pager is very powerful, but the main feature for me — displaying colored man-pages. This feature improves perception of plain text and eases searching of needed information.
Look at the attached screenshot, text looks very nice, isn’t it?
@ACK_stoverflow — probably not a good idea to recommend the guy to do > ~/.bashrc as it will overwrite what’s in there already. Better to append ( >> ) or add the lime manually in my opinion.
@vatsug Wow good call, here is what my comment should have said: Install it and try it out: aptitude install most; export MANPAGER=»most»; man man . To make it permanent: echo ‘export MANPAGER=»most»‘ >> ~/.bashrc
Don’t ignore the info pages. Many GNU tools have far more extensive info pages than man pages. Often, the SEE ALSO section will say «The full documentation for foo is maintained as a Texinfo manual.» This is especially true for anything in the GNU coreutils package.
Also, if you are an emacs user, don’t forget you can read info and manual pages without leaving your editor: M-x info and M-x woman .
In Linux man , you can do man -K string (note the uppercase K) to do a brute force search of a given term
-K, --global-apropos Search for text in all manual pages. This is a brute-force search, and is likely to take some time; if you can, you should specify a section to reduce the number of pages that need to be searched. Search terms may be simple strings (the default), or regular expressions if the --regex option is used.
very useful when you don’t know where to search.
From Kristof answer, if you (i.e.) type man -k chmod you’ll get a list of possibilites. Note the number in the parenthesis, it means the section to look for in the manual pages:
man -s1 chmod it will show the man page for chmod command
man -s2 chmod it will show the man page for the C lib function chmod()
On Linux you should change -s for -S
If you’re looking for information regarding a bash builtin (such as time , disown , set , or [[ ), instead of slogging through the detailed bash info page or man bash , you can enter help and get basic syntax information quickly.
For those longer, more complex man pages I find it much easier to read them away from a computer (odd, I know) and so I have these functions in my .bashrc
# Print man pages manp() < man -t "$@" | lpr -pPrinter; ># Create pdf of man page - requires ghostscript and mimeinfo manpdf() < man -t "$@" | ps2pdf - /tmp/manpdf_$1.pdf && \ xdg-open /tmp/manpdf_$1.pdf ;>
Dayum, people! What’s with the convoluted answers?! Whatever happened to simplicity being the key to brilliance and what not? Most of your vi/vim keys will work swimmingly:
/ or ? — Search forward or backward(as some of the guys have already mentioned). In case of the former, a lowercase n will scroll through matches forward, a capital N will go backward. The opposite is true for the latter-the question mark.
Slightly more complex searches through regular expressions. The difference between man (or less ) and VIM is that you have to use the escape() character to declare metacharacters in your expression when using the latter. The good news is that when you are using the former( man or less )-not so much. So you can easily put this to use when searching, for instance, an iptables man page for multiple terms like so: /(iptables|rules) . If your are unfamiliar with regular expressions, this means «Search for instances of words iptables OR rules «. After entering this and keeping on pressing n you will be scrolling through the alternating results of the search with the results being nicely highlighted for you with different colors(two, actually. Haha). If your are trying to skim through the page and want to concentrate on specific terms or concepts-you won’t miss a single thing!
And, of course, for faster navigation your regular vi standbies still stand(no pun intended): gg or G — beginning/end of document; (Correction! In man you can use all the keys mentioned below without using Ctrl. That’s for vi only). Ctrl + u or d — Scroll up or down; Ctrl + b or f — Same thing, only in bigger leaps. «Page backward or forward»; e or y — scroll by a single line, but I think most people would rather just use the arrow keys. However, if you want to stay «1337» and «never leave the home row»(like I do lol)-it’s the way to go.
What I’m trying to say is that UNIX has two main flavors of keyboard program controls, which are both parts of the readline library: vi and emacs. Up your chops in either one(but, preferably-in both) and it’ll make your life a lot less complicated. Most of the CLI programs in UNIX employ either one. BASH uses emacs controls by default, but it can easily be set to «vi mode» by typing in set -o vi . The same can be said for regular expressions, but that’s going to be way off-topic. I’d even go as far as to say that both of these are the «lingua franca» of UNIX.
How to search Linux man pages (e.g. with grep)
I’m looking for information on the -X option of curl . However, the documentation is quite lengthy and I have to scroll down for quite a long time to get to this option. Instead, I’d like to do something like
to get the line containing «-X». (I would also do this in conjunction with the option -A 10 to get the 10 lines after the match). However, if I try this I get
grep: option requires an argument -- 'X' Usage: grep [OPTION]. PATTERN [FILE]. Try 'grep --help' for more information.
Any ideas on how to use grep together with man , or more generally on how to search man pages for specific lines?
3 Answers 3
You have to tell grep that -X is not an option, but the pattern to look for:
— indicates the end of options. Without it, grep thinks that -X is an option.
Alternatively, you can use -e to indicate that what follows is a pattern:
If you want to see the complete man page but skip directly to the first occurrence of -X , you can use a command line option to less :
Typing N repeatedly then takes you to the following occurrences.
I did man curl | grep -a 20 — ‘-X’ together with the -a 20 option to read the first 20 lines below each result. This allowed me to quickly find the documentation on the -X option without having to scroll down too much.
@KurtPeek: you probably mean -A , because -a simply states that a binary files should be processed as text as well.
In MacOs, I want to get doc about find with arg -type , so I input man find | grep — ‘-type’ , but return this two pseudo-types, «local» and «rdonly». The former matches find / -type f -exec echo <> \;
On most Linux systems, the default pager used by man is less .
If that is the case, you can search in a man page using the / (slash) key followed by a query (here -X ) and finally hit ENTER . It will highlight all cases of -X . It is of course possible that the first «hit» is not the one you want. In that case you can hit N to go to the Next hit and so browse through the entire document. In case you have jumped too far, you can use Shift + N to jump back to the previous hit.
This is not really an answer to the question how to handle this with grep , but it is simply a way to efficiently search in man .
You can read the man page of less ( man less ) for further tricks on how to effectively use less to improve your experience with man pages.
man will implicitly open in less if you have it installed. So maybe you could read man page for less .
less actually supports search on it’s own. Just press / and write what you wanna search and enter . Use n to skip to next occurrence and N for previous.
Be careful when stating man will implicitly open in less . On most systems this is the case but some Linux distros might opt for another one and furthermore a user can set the $PAGER or $MANPAGER variables and alter the pager that is used.