Using the Linux apropos command – even if you have to fix it first


On Linux, the apropos command helps identify commands related to some particular term. It can be helpful in finding commands you might want to use—especially when you can’t remember their names.

For example, if you couldn’t remember the command to display a calendar or put your shell to sleep for a short period of time, you could try these commands:

$ apropos calendar
cal (1)              - display a calendar
$ apropos sleep
sleep (1)            - delay for a specified amount of time
usleep (1)           - sleep some number of microseconds

For some arguments, like “file”, you will get a long multi-page listing because so many Linux commands work with files. My system identifies 368 such commands.

$ apropos file | wc -l
368

If you use Linux often, you may not need to be reminded about many command names. On the other hand, apropos can sometimes help users discover commands that they might not have tried before. Run the command apropos edit, for example, and you might be surprised to see a lot more than vi and nano in the commands listed.

You can also type only a portion of a command name to get a listing of commands containing that substring.

$ apropos xz
unxz (1)             - Compress or decompress .xz and .lzma files
xz (1)               - Compress or decompress .xz and .lzma files
xzcat (1)            - Compress or decompress .xz and .lzma files
xzcmp (1)            - compare compressed files
xzdec (1)            - Small .xz and .lzma decompressors
xzdiff (1)           - compare compressed files
xzegrep (1)          - search compressed files for a regular expression
xzfgrep (1)          - search compressed files for a regular expression
xzgrep (1)           - search compressed files for a regular expression
xzless (1)           - view xz or lzma compressed (text) files
xzmore (1)           - view xz or lzma compressed (text) files

Nothing appropriate

If you try the apropos command for obviously valid commands and keep getting the response “nothing appropriate”, you might have to make an important update to get it working again. For the most part, you should only see a response like this for commands that don’t exist or that you misspell. If you get this response repeatedly, you might need to address the problem.

$ apropos cal
cal: nothing appropriate.

Since I hadn’t used apropos in quite a while, getting only “nothing appropriate” responses left me wondering why apropos had stopped working and when. It took a bit of head scratching and hunting around before I discovered the mandb command that allowed me to get apropos working again. The mandb command will create or update the manual page index caches, and this turned out to be what my system required. I ran the command as root and then watched as the output filled my screen and kept going.

# mandb
Processing manual pages under /usr/man...
Updating index cache for path `/usr/man/man1’. Wait...mandb: warning: /usr/man/m
an1/grub2-emu.1.gz: whatis parse for grub2-emu(1) failed
mandb: warning: /usr/man/man1/grub2-mount.1.gz: whatis parse for grub2-mount(1)
failed
Updating index cache for path `/usr/man/mann’. Wait...done.
Checking for stray cats under /usr/man...
Checking for stray cats under /var/cache/man/fsstnd...
Processing manual pages
…

One of the intriguing things that I noticed in the mandb output was the many references to “stray cats”. These would be files created by the catman command that use a different structure than is used for man pages, making displaying them faster than displaying the original man pages. The mandb command checks for them whether or not they exist on your system.

Wrap-Up

The apropos command is helpful when you’re searching for commands you can’t remember or looking to discover some that you might not have used before. Fortunately, the “nothing appropriate” problem is easy to resolve and there really aren’t a lot of stray cats hiding in your Linux system.

Join the Network World communities on Facebook and LinkedIn to comment on topics that are top of mind.

Copyright © 2022 IDG Communications, Inc.



Source link