In Linux, if you ever need help regarding a command, all you need to do is to open its man page. But what if a situation arises wherein the requirement is to quickly search the names and descriptions of all available man pages? Well, Linux has got your covered, as there exists a command dubbed apropos that does exactly this for you.
In this tutorial, we will discuss the basics of apropos using some easy to understand examples. But before we do that, it’s worth mentioning that all examples here have been tested on an Ubuntu 16.04 LTS machine.
On this page
- Q1. How to use apropos?
- Q2. How to make apropos search for exact keywords?
- Q3. How to make apropos display entries matching all keywords?
- Q4. How to force apropos to not trim output?
- Q5. How to interpret apropos exit status?
Linux apropos command
The apropos command searches manual page names and descriptions for a user-supplied keyword. Following is its syntax:
apropos [OPTIONS] keyword ...
apropos [-dalhvV] [-e|-w|-r] [-s list] [-m system[,...]] [-M path] [-L locale] [-C file] keyword ...
And here’s what the tool’s man page says about it:
Each manual page has a short description available within it. apropos
searches the descriptions for instances of keyword.
keyword is usually a regular expression, as if (-r) was used, or may
contain wildcards (-w), or match the exact keyword (-e). Using these
options, it may be necessary to quote the keyword or escape (\) the
special characters to stop the shell from interpreting them.
The standard matching rules allow matches to be made against the page
name and word boundaries in the description.
The database searched by apropos is updated by the mandb program.
Depending on your installation, this may be run by a periodic cron job,
or may need to be run manually after new manual pages have been
Display all manual entries with the word “find” in the page name or description. Output resembles the following:
aa_find_mountpoint (2) - find where the apparmor interface filesystem is mounted chkdupexe (1) - find duplicate executables ffs (3) - find first bit set in a word ffsl (3) - find first bit set in a word ffsll (3) - find first bit set in a word find (1) - search for files in a directory hierarchy find2perl (1) - translate find command lines to Perl code findaffix (1) - Interactive spelling checking findfs (8) - find a filesystem by label or UUID findmnt (8) - find a filesystem findsmb (1) - list info about machines that respond to SMB name quer... glob (3) - find pathnames matching a pattern, free memory from gl... globfree (3) - find pathnames matching a pattern, free memory from gl... ippfind (1) - find internet printing protocol printers lfind (3) - linear search of an array locate (1) - find files by name memdiskfind (1) - utility to search for a MEMDISK instance mlocate (1) - find files by name mysql_find_rows (1) - extract SQL statements from files oldfind (1) - search for files in a directory hierarchy pidof (8) - find the process ID of a running program. texdoc (1) - find & view documentation in TeX Live tfind (3) - manage a binary tree tracediff (1) - find and print differences between two traces ttyslot (3) - find the slot of the current user's terminal in some file
Following are some Q&A-styled examples that should give you a good idea on how the apropos command works.
Q1. How to use apropos?
Basic usage is simple. Just pass the keyword you want to search as input to the apropos command.
produced the following result:
dmesg (1) - print or control the kernel ring buffer
Of course, you can pass multiple keywords as well.
apropos dmesg whereis
Following is the output in this case:
dmesg (1) - print or control the kernel ring buffer
whereis (1) - locate the binary, source, and manual page files for a...
Q2. How to make apropos search for exact keywords?
By default, the input you pass to the apropos command isn’t searched exactly. For example, if you pass ‘who’ as an input, you’ll also see the tool producing results containing words like ‘whoami’.
So this isn’t an exact search. However, you can force apropos to search for exact keywords by using the -e or –exact command line options.
So now you see that only those entries that exactly match ‘who’ were displayed in the output.
Q3. How to make apropos display entries matching all keywords?
If you pass multiple keywords as input to the apropos command, the tool will output entries that match/contain at least one of the keywords. However, if you want apropos to produce only those entries that match/contain all keywords, then use the -a command line option.
For example, here’s the output of an apropos command without the -a option:
And here’s the output with -a option enabled:
Q4. How to force apropos to not trim output?
As you’d have seen in output in previous Q&As, the tool trims entries if they are too long. For example, see the highlighted line in the following output:
However, if you want, you can force apropos to produce complete lines in output, something which you can do using the -l command line option.
Q5. How to interpret apropos exit status?
The apropos command produces four different exit status: 0, 1, 2, and 16. Here’s what each of these represents:
0 Successful program execution.
1 Usage, syntax or configuration file error.
2 Operational error.
16 Nothing was found that matched the criteria specified
Depending on your work profile, you might not require the apropos command on daily basis, but as you’d have understood by now, it could be a lifesaver in certain situations. We’ve discussed some use command-line options here. To know more about the tool, head to its man page.