Code Matters

Search Man Pages With Apropos

June 13, 2021

Unix man pages are a mixed bag, but they’re faster than Google if you know where to look. That’s where the apropos program comes in. E.G. to search for man pages for errno:

$ apropos errno
clnt_perrno (3)      - library routines for remote procedure calls
clnt_sperrno (3)     - library routines for remote procedure calls
errno (3)            - number of last error
h_errno (3)          - get network host entry

This returns the man page name and section number (run man man for a list of section numbers and their meaning). In this case all the results are in section 3, Library calls.

It finds matches by looking for instances of the search term in the man page name and description. By default apropos treats the search term like a regex, which is why it returned substring matches like “clnt_perrno”. Use the -e flag for exact matches:

$ apropos -e errno
errno (3)            - number of last error

This output tells me I can read the errno man page via man 3 errno.

You can also search man pages with man -k, which is easier to type but it does not support all the options that apropos does (like -e). I’ve heard that some proprietary Unixes do not have the apropos program. If man is your only option, or if that’s what you prefer to type, you can get an exact match by using an anchored regex:

$ man -k '^errno$'
errno (3)            - number of last error

Tags: unix manual documentation apropos