Use apropos command to search across Linux command name, title and description
Every manpage has a title and short description. apropos searches the title and descriptions for instances of keywords. The description's word boundaries and the page name can both be matched using the regular matching criteria.
The man-db program updates the database that apropos searches. Depending on your installation, this could need to be manually executed once new manual pages have been installed, or it might be done on a regular basis by a cron job in the background.
apropos
command syntax
apropos [-dalv?V] [-e|-w|-r] [-s list] [-m system[,...]] [-M path] [-L locale] [-C file] keyword ...
Install apropos
command
Debian based - apt install man-db
Alpine - apk add man-db
Arch Linux - pacman -S man-db
CentOS - yum install man-db
Fedora - dnf install man-db
OS X - brew install man-db
Raspbian - apt-get install man-db
apropos
command options
-r , --regex |
Interpret each keyword as a regular expression. (This is the default behavior.) |
-w , --wildcard |
Interpret each keyword as a pattern containing shell style wildcards. Each keyword will be matched against the page names and the descriptions independently. |
-e , --exact |
Each keyword will be exactly matched against the page names and the descriptions. |
-a , --and |
Only display items that match all the supplied keywords. The default is to display items that match any keyword. |
-l , --long |
Do not trim output to the terminal width. Normally, output will be truncated to the terminal width to avoid ugly results from poorly-written NAME sections. |
-s list , --sections=list , --section=list |
Search only the given manual sections. list is a colon or comma-separated list of sections.
|
-m system[,...] , --systems=system[,...] |
If this system has access to other operating system's manual page descriptions, they can be searched using this option. To search New OS's manual page descriptions, use the option -m NewOS .
The system specified can be a combination of comma-delimited operating system names. To include a search of the native operating system's descriptions, include the system name man in the argument string. This option will override the $SYSTEM environment variable.
|
-M path , --manpath=path |
Specify an alternate set of colon-delimited manual page hierarchies to search. By default, apropos uses the $MANPATH environment variable, unless it is empty or unset, in which case it will determine an appropriate manpath based on your $PATH environment variable. This option overrides the contents of $MANPATH . |
-L locale , --locale=locale |
apropos will normally determine your current locale by a call to the C function setlocale(3) which interrogates various environment variables, possibly including $LC_MESSAGES and $LANG . To temporarily override the determined value, use this option to supply a locale string directly to apropos . Note that it will not take effect until the search for pages actually begins. Output such as the help message will always be displayed in the initially determined locale. |
-C file , --config-file=file |
Use this user configuration file rather than the default of ~/.manpath . |
--usage |
Print a short usage message and exit |
-v , --verbose |
Print verbose warning messages. |
-? ,--help |
Display this help message and exit. |
--version |
Output version information and exit. |
|
|
apropos
command example
1. Search relevant keywords with apropos
command. (regex)
The keyword is usually a regular expression by default. Same as if -r
or -regex
was used, or may contain wildcards -w
/–wildcard
, or match the exact keyword -e
/–exact
. Using these options, it may be necessary to or escape \
the special characters to stop the shell from interpreting them or you can delimit these with single quotes 'regex'
. Each keyword will be independently matched against the page titles and descriptions. Any component of either can be matched. There is no word restriction on the contest.
Here, let’s search every command which has an exact keyword match.
$ apropos extract
ar (1) - create, modify, and extract from archives
funzip (1) - filter for extracting from a ZIP archive in a pipe
git-get-tar-commit-id (1) - Extract commit ID from an archive created using git-archive
git-mailinfo (1) - Extracts patch and authorship from a single e-mail message
ifnames (1) - Extract CPP conditionals from a set of files
...
2. Search wildcard keywords with apropos
command.
Consider every keyword to be a pattern with shell-style wildcards. A match will only be made if an extended keyword matches the entirety of a description or page name if the --exact
option is also used. In the absence of it, the keyword is also permitted to match on description word boundaries.
Let’s use wildcards to search for all keywords starting with ‘extract
’ and end with ‘g
’:
$ apropos -w 'extract*g'
funzip (1) - filter for extracting from a ZIP archive in a pipe
unzipsfx (1) - self-extracting stub for prepending to ZIP archives
When exact is used with wildcards:
$ apropos -e -w 'extract*g'
extract*g: nothing appropriate.
3. Search multiple keywords with apropos
command.
We can use -a
or --and
to search for all the supplied keywords. The default is to display items that match any keyword.
$ apropos archive -a extract -a zip
funzip (1) - filter for extracting from a ZIP archive in a pipe
unzip (1) - list, test and extract compressed files in a ZIP archive
unzipsfx (1) - self-extracting stub for prepending to ZIP archives
4. Search keywords on the specified manual section with apropos
command.
Look solely in the manual's designated sections. list is a list of sections that are separated by commas or colons. If an entry in list has an extension, such as "3perl" then the list will only include pages in that specific part of the manual section. For example, if an entry in list is a simple section, such as "3" then the displayed list of descriptions will include pages in sections "3", "3perl", "3x", and so on.
We may use -s list
, --sections=list
, --section=list
to specify the section.
$ apropos extract -s 8
unmkinitramfs (8) - extract content from an initramfs image
Conclusion
In this article, we explored one of the most useful Linux commands named apropos
. It is basically used to search a keyword through a manual page database (man-db
) to find desired linux command or function. Since Linux man-db
is divided into different sections, we can also specify the section to get desired output.