home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Complete Idiot's Guide to Linux
(Publisher: Macmillan Computer Publishing)
Author(s): Manuel Ricart
ISBN: 078971826x
Publication Date: 12/22/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Searching for a Tool: apropos

Man is very useful if you know the name of the command you’re interested in. You can do a man commandname, and you are on your way. But what if you don’t know the name of the command you are looking for?

That is where the apropos command comes in: It allows you to search for keywords instead. As a result, it displays a list of documents that might be related to your question.

Great! There’s only one small hang-up: the database that apropos searches, called the whatis Database, does not exist until you create it. (You’ll learn how to do this in the section “Building the whatis Database: makewhatis.”) After you build it, you can query the database with the apropos command, for example, to find out about commands related to your tape drive:

     [alberto@digital alberto]$ apropos tape
     mt (1)               - control magnetic tape drive operation
     smbtar (1)           - shell script for backing up SMB shares directly
     to UNIX tape drive
     st (4)               - SCSI tape device

From this information, you know that there are at least three manual pages (use the man command) that relate to your tape drive. The numbers you see in parenthesis indicate a manual section.

The UNIX manual is organized into several sections. Each section is organized by topic. Table 15.1 provides a list of the sections.

Table 15.1 Sections of the UNIX Man Pages Under Linux

Section Number Topic

1 User commands, programs, and applications
2 System calls and kernel error codes
3 Library function calls
4 Special files (things in /dev directory)
5 Standard file formats
6 Games and other funny-type programs
7 Miscellaneous things that don’t fit elsewhere
8 System administration commands, programs, and applications

If you don’t specify a section, man will search sections that cover commands first; typically, the order will be sections 1, 8, and 6.

It is possible that a command is described in more than one section of the manual. To view a document specific section, specify the man command like this:

  man section command

In the preceding example, the man command is listed twice: in sections 1 and 7. To read the information on section 7, enter this command:

  man 7 man

Getting a Brief Command Description: whatis

Sometimes you don’t care to read five paragraphs of the UNIX manual just to find out what a command does. In those cases, the whatis tool can also be used to obtain a brief description of the command. To operate in this mode, you provide the name of the tool as an argument.


Check This Out:  Building the whatis Database: makewhatis
To build the whatis database, you’ll need to use the makewhatis command. To start building the database, enter this command:
   /usr/sbin/makewhatis

Note that you must be root (you can also be su and execute the command) in order for this program to work properly. After a few moments, the database will be built. If you have an older computer, this action could take a while.


whatis will print out a one-line description of what a command does. I have found that whatis is a great exploration tool. If you go into a program directory such as /sbin, you can quickly learn what the commands there do by issuing this command:

     cd directory; whatis *

This will take you to the directory you specify under directory and issue a whatis on all the files that it finds there. The * is a regular expression that specifies all files it finds in that directory:

     [alberto@localhost alberto]$ cd /sbin; whatis *
     adjtimex (2)         - tune kernel clock
     adjtimex (8)         - display or set the kernel time variables
     arp (8)              - manipulate the system ARP cache
     (And more...)

Searching Standard Locations: whereis

Sometimes the help you need is in locating the file or program you’re looking for. As explained earlier, your shell finds commands by looking into your environment variable. When you issue the name of a command, the directories listed in the PATH environment variable are searched for a matching command. If found, the command is executed; otherwise, you get the dreaded “command not found” response.

Because some directories holding tools are not included in the default user path, your shell will not see them. In those cases, you can use the whereis tool to find the actual path to the tool you want to use.


Note:  
For more information on regular expressions, take a look at Chapter 14, “Putting the Shell to Work.”

Not only does whereis locate a binary, but it will also locate source and manual pages having the name you provide. The format for the command is this:

     whereis command

In the following example, I search for the command passwd:

     [alberto@digital alberto]$ whereis passwd
     passwd: /usr/bin/passwd /etc/passwd /etc/passwd.OLD
     /usr/man/man1/passwd.1 /usr/man/man5/passwd.5

Built-in Command Information

Most recent commands store basic usage information right in the program. Under Linux, you can always try the command name with a --help or -h argument. Typically, the information listed will span more than one screen, so remember to pipe the output through less:

     commandname --help | less

If the command you are using is a “smart” UNIX command, it will respond in a reasonable way even if it does not understand the --help flag. Typically, when a program encounters an unknown argument, it reverts to spewing its usage information. The usage information will tell you the basic format of the command along with the flags that it supports. Obviously, this won’t tell you what the program does (unless you already know), but some information is better than none at all. If man failed, you might need to surf the Web to find some information. I have found that searching the command name in an engine such as Yahoo usually points me in the right direction.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.