89

Does anyone have any tricks and tips for finding information in man pages?

2
  • 1
    man --help/man -h and its more complete sibling man man has search and navigation tips. Nov 16, 2017 at 16:31
  • To start a man page and search for a pattern: man -P'less +/pattern' bash Feb 3, 2020 at 18:59

25 Answers 25

64

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.

0
53

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

3
  • 11
    On most systems you can check out man man to see a full description of the various sections.
    – Steven D
    Sep 10, 2010 at 15:30
  • 1
    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.
    – Hi-Angel
    Oct 30, 2014 at 10:47
  • 3
    @Hi-Angel man -k substring or apropos substring would have helped you.
    – Kusalananda
    Dec 29, 2016 at 16:32
38

man -k search

This will give you a list of all man pages which relate to 'search'.

2
  • 2
    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
    – kenichi
    Jan 18, 2017 at 14:55
  • apropos search is equivalent to man -k search :)
    – b0yfriend
    Jun 17, 2020 at 8:21
22

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:

info gpg |less

This way, I can navigate the info pages using my favorite pager. The info pages will now behave the same as man pages.

1
  • 1
    hey, that's a great tip about the navigation Sep 20, 2018 at 14:52
19

The default pager for reading a man page is less. There is documentation on less here.

In particular:

  • 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.
  • Add an @ before the regular expression to search from the start.
2
  • THIS is the best answer. Extra points for using kbd symbols. ;)
    – Chiramisu
    Jan 25, 2019 at 0:06
  • 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. Oct 6, 2019 at 19:28
18

The apropos utility is seriously handy for finding the appropriate manpage.

3
  • 3
    man -k == apropos, isn't it?
    – phunehehe
    Sep 10, 2010 at 15:49
  • 1
    apropos is what I use all the time when looking for something that has not man page for itself.
    – polemon
    Sep 10, 2010 at 18:51
  • 2
    '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. Sep 11, 2010 at 11:25
8

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.

7

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' -"
5

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?

most pager

3
  • 2
    You have left out the most important piece of information: how do I use most to view man pages. May 28, 2013 at 18:12
  • 2
    @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.
    – anaotha
    Dec 30, 2016 at 9:20
  • @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 Jan 3, 2017 at 16:35
4

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.

0
4

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.

3

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:

On UNIX you can try:

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

1
  • man 1 chmod man 2 chmod does the same thing. Mar 6, 2018 at 0:07
3

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 {builtin-keyword} and get basic syntax information quickly.

3

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 ;}
3

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.

1
  • the multiple search terms feature is great! i've used more/less for forever and didn't realize it was available. Aug 18, 2021 at 5:21
2

View man pages in a user-friendly graphical application:

konqueror man:(command)

For the top-level table of contents:

konqueror man:

Features:

  • If you enter a command that has a match in multiple sections, it takes you to a disambiguation page
  • It's a graphical application, so you don't have to remember cryptic key sequences to navigate the page
  • It includes hyperlinks to related pages (including "see also" pages)
  • You can open related pages in separate tabs
4
  • By the way, this also works with info:(command). Some programs provide a lot more information via "info" than via "man", and konqueror provides a much nicer interface for browsing these info pages. Note: Just using info:, also works for getting a top-level table of contents. Feb 13, 2012 at 2:45
  • A similar effect can be achieved using the gman package which establishes a manpage webserver at localhost/cgi-bin/man/man2html. Jun 22, 2013 at 17:58
  • Alternatives on AskUbuntu: askubuntu.com/questions/253705/… Nov 12, 2015 at 1:44
  • ...yelp being a lighter-weight drop-in replacement for konqueror -- although it has the deficiency of not presenting a table of contents or a disambiguation page for names used in multiple sections. You have to differentiate these explicitly by appending .(section) -- e.g. yelp man:open.2. You can also use <kbd>Ctrl-L</kbd> to open the location bar. Dec 1, 2015 at 15:44
2

Similar to but slightly different from Rob Hoelz's answer,

Add the following in your ~/.vimrc:

let $GROFF_NO_SGR=1
runtime ftplugin/man.vim

Now vimman is an excellent manpage viewer, and :Man from within Vim (or simply hitting K over a keyword) is an excellent manpage browser.

1

Most of us set the PATH variable. This will show you how to automatically make the man search path match your command search PATH.

Say you append your path to include your personal, work-specific and locally-installed utilities, like export PATH=$PATH:~/bin:/workgroup/bin:/opt/local/bin:. As a side effect, man foo won't show the manpages stored at ~/man , /workgroup/man or /opt/local/man .

To resolve this, I use the manpath command to automatically set the man page search path. For example, my ~/.bashrc has the following. This works for me on a hundred different systems running everything from FreeBSD 4.x, Darwin and CentOS 5:

### PATH & MANPATH
# My personal utilities
export PATH=$PATH:$HOME/bin

### Set the manpath based on the PATH, after man(1) parses man.conf
# - No need to modify man.conf or manually modify MANPATH_MAP
# - Works on Linux, FreeBSD & Darwin, unlike /etc/manpaths.d/
# See "SEARCH PATH FOR MANUAL PAGES" in man(1)
# Just set the man search path. Don't print output to screeen.
manpath >/dev/null

Some systems (Like Apple Leopard) set the MANPATH automatically, but that means that your system will use the MANPATH variable instead of using manpath. As a result, man pages for 'MacPorts' (/opt/local/man) are ignored. I want to control this myself, so I unset MANPATH:

unset MANPATH
manpath >/dev/null
1

If you are annoyed that man printf gives you printf(1) and all you want is printf(3), you can tell man you want the printf from section 3 by putting the section before printf, like so: man 3 printf, without having 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.

1

I just use grep. If i were to wonder what the -s option of the read command did, i'd try these commands in order until i got an answer:

info read |grep \\-s

man read |grep \\-s

help read |grep \\-s

In this case only the info command provided a clear answer. This excellent answer gives the details on the different help systems.

1

man -a printf just defaults to man 1 on my Linux Mint machine. whatis printf gives me the pertinent information.

1

enter image description hereIf you find it hard to read the manpages because of all white colored text, you can colorize them. Most man pages open with less. For less, I use the following color settings in .bashrc from here:

man() {
    LESS_TERMCAP_md=$'\e[01;31m' \red
    LESS_TERMCAP_me=$'\e[0m' \
    LESS_TERMCAP_se=$'\e[0m' \
    LESS_TERMCAP_so=$'\e[01;44;33m' \yellow on blue
    LESS_TERMCAP_ue=$'\e[0m' \
    LESS_TERMCAP_us=$'\e[01;32m' \green
    command man "$@"
}

This is for bash and zsh. For most, fish, xterm and rxvt see the link above.

For further reading:

1

To look efficiently for single character switch, for example -u, you can often use:

/^ *-u($|\s)

Saves a lot of time if many options have '-u' as prefix.

1
  • Also, this regex would be useful: /-u($|[,\s]) in case option character is framed with comma. But if you want to see all entries of the option character 'u' (like -u] in [--udp|-u] of netstat manual) you'll need something like this: /-u($|[^a-z]) And if vi or vim is used as pager: /-u\($\|[^a-z]\)
    – kenichi
    Jan 18, 2017 at 14:37
0

The apropos(1) command is used for searching man pages. However, most implementations of apropos(1) just search in the NAME section, which is very limiting.

NetBSD has a full text search implementation of apropos(1), which is capable of searching the complete content of man pages. There is also a web based interface for it: man-k.org, that you can try out.

0

And for those folks who like to read man and info pages in a touchscreen you can pipe man/info to yad or zenity and make use of all gtk3 goodies like native finger scroll. Also works great with refular screen and mouse :

man cat |yad --text-info 

You can use also zenity or you can add yad options like:

man cat |yad --text-info --height=500 --width=800 --center --wrap --show-uri --no-markup &

Tip: by show uri yoh can click on web links inside man pages with mouse/finger.

Not the answer you're looking for? Browse other questions tagged .