Beginner’s Guide to Using the Linux ‘whatis’ Command: 5 Practical Examples

Man pages are invaluable resources for understanding command-line utilities, but they can sometimes be overwhelming due to their detailed content. If you’re looking for a quick, concise description of a command-line tool, the whatis command is precisely what you need.

This guide will walk you through the basics of the whatis command using straightforward examples. Note that these examples have been tested on Ubuntu 18.04 LTS and Debian 10.

The Linux whatis Command

The whatis command in Linux displays one-line manual page descriptions. Its syntax is as follows:

whatis  [-dlv?V]  [-r|-w]  [-s  list]  [-m  system[,...]] [-M path] [-L
       locale] [-C file] name ...

The tool’s manual page provides this explanation:

Each manual page has a short description available within it. whatis searches the manual page names and displays the manual page descriptions of any name matched. Name may contain wildcards (-w) or be a regular expression (-r). Using these options, it may be necessary to quote the name or escape (\) the special characters to stop the shell from interpreting them.

Below are some Q&A styled examples to help you understand how the whatis command functions:

Q1. How to Use the whatis Command?

Basic usage is straightforward. Simply pass the name of the tool, and whatis will search and give you a one-line description.

Example:

whatis ls

Output:

ls (1)              - list directory contents

Q2. How to Get Information on Multiple Commands?

To get descriptions for multiple commands, pass the list of tool names to whatis:

whatis ls cp rm mv

Output:

ls (1)              - list directory contents
cp (1)              - copy files and directories
rm (1)              - remove files or directories
mv (1)              - move (rename) files

Q3. Can Wildcards Be Used with whatis?

Yes, you can use wildcards with whatis by enabling the -w option.

Example:

whatis -w 'who*'

Output:

who (1)             - show who is logged on
whoami (1)         - print effective userid

Q4. How to Make whatis Produce Debugging Information?

The -d option allows whatis to produce debugging information, primarily for developers.

Example:

whatis -d ls

Output:

/* Extensive debugging information specific to your system configuration and paths */

Q5. How Does whatis Perform Its Searches?

Here’s an excerpt from the manual explaining the search mechanism:

Index databases are used during the search, and are 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 installed. To produce an old style text whatis database from the relative index database, issue the command:

whatis -M manpath -w '*' | sort > manpath/whatis

where manpath is a manual page hierarchy such as /usr/man.

Conclusion

If you frequently use Linux command-line tools or deal with man pages, the whatis command can be an invaluable tool. We’ve covered a few command-line options here. For further details, please refer to the tool’s man page.

FAQ

Q: Can I update the whatis database automatically?
A: Yes, using the mandb command, you can update the database manually or configure it to run periodically via cron jobs.

Q: Is whatis available on all Linux distributions?
A: The command is commonly found on most UNIX-like systems, but availability can vary based on the specific Linux distribution and its installed packages.

Q: Can I limit whatis to search particular sections of the man pages?
A: Yes, use the -s option followed by the section numbers you wish to query.