Using apropos command with -a to search multiple keywords on CentOS 7

command linemanoptionssearch

I'm running CentOS 7.0 build 1503. I'm trying to search for commands I don't know the name of by searching the man descriptions for multiple keywords using AND (e.g. search for a command containing the both words "create" and "group" in the description).

So I came across the command apropos (which is an alias for man -k). The default behaviour when given multiple keywords is to return any command matching any of the keywords, which isn't what I want. According to the man page the option -a specifies using AND, to return matches only when all words match.

But this isn't what I'm seeing in practice, so I need some help here – e.g. using Centos 7, if I do:

apropos create user

I see a huge list of commands, seemingly matching any command with create or user in the description, as expected. Noting the list includes an entry for the command 'useradd (8) – create a new user…'.

If I do:

apropos -a create user

I only get 2 commands (environ and open). This is what I'm confused by – I would expect it to return the command 'useradd (8) – create a new user', because i can see from the previous search that command does contain those words in the description. Also the 2 returned commands don't obviously seem to be anything about creating users. What am I doing wrong? I'm sure it's something embarrassingly obvious, for that I apologise in advance.

Thanks

Best Answer

The apropos command reads from a cache. It's possible that recently-installed man pages are not yet referenced in that cache. Generally the cache is updated either after each package installation or in a cron job, I don't know how it's set up on CentOS.

To update the cache, run mandb. There may be a prefered way to run it on your distribution (e.g. as a dedicated user), see if you have a system crontab entry (e.g. /etc/cron.daily/man-db or a line in /etc/crontab) and if you do, run that instead of calling mandb directly.

Related Question