12. The Whatis and Apropos Commands
During your Linux exploration, it sometimes happens that you forget a command or two or misremember what it does. This is especially true for those of us whose years of Windows use has caused command-line synapses in our brains to atrophy. Luckily, Linux takes this into consideration and has a solution to help retrieve those commands that have escaped into the forgettery. We'll tell ya all about it.

Important: The tips in this document require the use command-line commands. For more information about how to read and execute Linux command-line prompts and commands, please check the Linux Clues' Linux Cheat Sheet, especially Linux Prompt Basics and Linux Command-Line Nomenclature.

The Whatis Command
Whatis is a funny command that's bound to come in handy, especially while you're learning Linux. By typing "whatis" followed by a command, Linux returns the first line of the Man-page (manual page) for that command. Here's an example to show you what the "cp" command does:

$ whatis cp

This returns:
cp (1) - copy files and directories

The command is listed followed by a number in parentheses. The number refers to the section of the man-pages (manual pages) that the command can be found in.

For the command ifconfig:

$ whatis ifconfig
ifconfig (8) - configure a network interface

If you wanted more information about one of the commands -- how it works and what the optional arguments are -- you would type:

$ man ifconfig

And get back the explanation, all 176 lines worth.

NOTE: Some distros won't have a pre-built Whatis database. Instead of the descriptions above, you'll see a response telling you to build the database. In that case log on as root and type:

# /usr/sbin/makewhatis

Up a Notch
But that's just the beginning of what you can do with whatis. Imagine you want to see a cheatsheet of commands in, let's say, the /usr/bin directory, for example. First change to that directory:

$ cd /usr/bin

Then type this command:

$ ls | xargs whatis | less

(Note: The "|" is a pipe, also known as the "Shift \" key.)

The beginning of the list looks like the following, with some minor variations depending on which distro you're running. It's a scrollable list; just press the spacebar to advance the page. To exit the list, press the Q key.

411toppm (1) - convert Sony Mavica .411 image to PPM
a2p (1) - Awk to Perl translator
a2ps (1) - format files for printing on a PostScript printer
abiword@: nothing appropriate
AbiWord-2.0*: nothing appropriate
access (1) - determine whether a file can be accessed
access (2) - check user's permissions for a file
access (5) - format of Postfix access table
aclocal@: nothing appropriate
aclocal-1.4*: nothing appropriate
aconnect (1) - ALSA sequencer connection manager
acroread@: nothing appropriate
activation-client*: nothing appropriate
adddebug*: nothing appropriate
addftinfo (1) - add information to troff font files for use with groff
addr2line (1) - convert addresses into file names and line numbers
addresses (1) - Dumps Palm Address Book to STDOUT in simple format

Advanced Tip
If you're the type who can't leave well enough alone, here's an explanation of the command you just typed:

$ ls | xargs whatis | less

ls = list directory contents
xargs = build and execute command lines from standard input
less = opposite of more (Just kidding, actually this reads input and renders it into a page.)

As you can see from the command list above, Access, for example, has multiple listings because it's listed in the manual several times. "Nothing appropriate" means there is no Man-page entry for that command.

Secret Sauce
Though you can run Whatis almost anywhere, there are some places it's more interesting to use than others. Try it here:

/bin
/usr/bin/
/sbin
/usr/sbin
/usr/X11R6/bin

Apropos
Because Linux knows so many commands, it's impossible to remember them all. (See, it's not just GUI-itis!) So here's a trick to help you. From a previous Linux Explorers tip you should know that if you type the first few characters of a command and press the Tab key, Linux will auto-complete the command or present you with a list of options for auto-completion:

We're going to be tricky and combine that feature with Whatis to really jog your memory, using the Apropos command.

Imagine you know only a part of the name or description of a command. Say for example, you remember "alsa," but not the whole of the command. Type:

$ apropos alsa

This returns:

aconnect (1) - ALSA sequencer connection manager
alsaconf (8) - config tool for the Advanced Linux Sound Architecture
alsactl (1) - advanced controls for ALSA soundcard driver
alsamixer (1) - soundcard mixer for ALSA driver, with ncurses interface
amidi (1) - read from and write to ALSA RawMIDI ports
amixer (1) - command-line mixer for ALSA driver
aplay (1) - command-line sound recorder and player for ALSA driver
arecord [aplay] (1) - command-line recorder/player for ALSA driver
aseqnet (1) - ALSA sequencer connectors over network

If you still weren't sure, you could use "$ man {command}" to get more information about each command.

Well, that is pretty cool isn't it? Very cool! But how cool is Linux, really? Way cool. Trust us.

$ apropos cool

Smalledit-3.17.7 (1) - Stripped down version of Cooledit text editor
cooledit (1) - Full featured X Window text editor for the System, v.11
coolicon (1) - Icon manager with graphical icon and drag and drop
coolman (1) - X Window Man page reader based on the Coolwidget library
sane-coolscan (5) - SANE backend for Nikon film-scanners

They don't come cooler than that, do they?