• Aucun résultat trouvé

The man command offers documentation for most commands that are available on your system.

Almost all commands listen to the --help argument as well. This will display a short overview of available options that can be used with the command on which you use the --help option.

For Bash internal commands, there is the help command. This command can be used with the name of the Bash internal command about which you want to know more. For example, use help for to get more information about the Bash internal command for.

An internal command is a command that is part of the shell and does not exist as a program file on disk. To get an overview of all internal com-mands that are available, just type help on the command line.

For almost all programs that are installed on your server, extensive documentation is available in the directory /usr/share/doc.

Using man to Get Help

The most important source information available for use of Linux commands is man, which is short for the system programmer’s “manual.” Think of it as nine different books

c02.indd 61

c02.indd 61 1/8/2013 10:42:26 AM1/8/2013 10:42:26 AM

called sections) is still present in the man command; therefore, you will fi nd a list of the available sections and the type of help you can fi nd in each section.

Looking for a quick introduction to the topics handled in any of these sections?

Use man n intro. This displays the introduction page for the section you’ve selected. Table 2.1 provides an overview of the sections that are used in man.

TA B L E 2 .1 Overview of man sections

Section Type Description

0 Header files These are files that are typically in /usr/include and contain generic code that can be used by your pro-grams.

1 Executable programs or shell commands

For the end user, this is the most important section.

Normally all commands that can be used by end users are documented here.

2 System calls As an administrator, you won’t use this section frequently. The system calls are functions that are provided by the kernel. This is very interesting if you are a kernel debugger or if you want to do advanced troubleshooting of your system. Normal administra-tors, however, do not need this information.

3 Library calls A library is a piece of shared code that can be used by several different programs. Typically, you don’t often need the information here to do your work as a system administrator.

4 Special files The device files in the directory /dev are documented in here. It can be useful to use this section to find out more about the workings of specific devices.

5 Configuration files Here you’ll find the proper format that you can use for most configuration files on your server. If, for example, you want to know more about the way /etc/passwd is organized, use the entry for passwd in this section by issuing the command man 5 passwd.

6 Games Historically, Linux and UNIX systems were limited

in the number of games that could be installed. On a modern server, this is hardly ever the case, but man section 6 still exists as a reminder of this old habit.

c02.indd 62

c02.indd 62 1/8/2013 10:42:26 AM1/8/2013 10:42:26 AM

Section Type Description

7 Miscellaneous This section contains some information on macro pack-ages used on your server.

8 System administration commands

This section does contain important information about the commands you will use on a frequent basis as a system administrator.

9 Kernel routines This documentation isn’t part of a standard install. It contains information about kernel routines.

The most important information that you will use as a system administrator is in sec-tions 1, 5, and 8. Sometimes an entry can exist in more than one section. For example, there is information on passwd in section 1 and in section 5. If you just use man passwd, man would show the content of the fi rst entry it fi nds. If you want to make sure that all the information you need is displayed, use man -a yourcommand. This ensures that man browses all sections to see whether it can fi nd anything about your command. If you know beforehand the specifi c section to search, specify that section number as well, as in man 5 passwd, which will open the passwd item from section 5 directly.

The basic structure for using man is to type man followed directly by the command about which you seek information. For example, type man passwd to get more information about the passwd item. This will show a man page, as shown in Figure 2.4.

F I G U R E 2 . 4 Showing help with man

Man pages are organized in a very structured way that helps you fi nd the information you need as quickly as possible. The following structural elements are often available:

c02.indd 63

c02.indd 63 1/8/2013 10:42:26 AM1/8/2013 10:42:26 AM

Download from Wow! eBook <www.wowebook.com>

Synopsis Here you can fi nd short usage information about the command. It will show all available options and indicate whether it is optional (it will be between square brackets) or mandatory (it will not be between brackets).

Description The description gives a long explanation of what the command is doing.

Read it to get a clear and complete picture of the purpose of the command.

Options This is a complete list of all options that are available. It documents the use of all of them.

Files This section provides a brief list of fi les, if any, that are related to the command about which you want more information.

See Also A list of related commands.

Author The author and also the email address of the person who wrote the man page.

Man is a very useful way to get more information on how to use a given command. The problem is that it works only if you know the exact name of the command about which you want to know more. If you don’t, you can use man -k, which is also available as the alias apropos. The -k option allows you to locate the command you need by looking at keywords. This will often show a very long list of commands from all sections of the man pages. In most cases, you don’t need to see all of this information; the commands that are relevant for the system administrator are in sections 1 and 8. Occasionally, when you are looking for a confi guration fi le, section 5 should be browsed. Therefore, it is useful to pipe the output of man -k through the grep utility that can be used for fi ltering. For example, use man -k time | grep 1 to show only lines from man section 1 that have the word time in the description.

To use man, you rely on the whatis database that exists on your system. If it doesn’t, you’ll see a “nothing appropriate” message on everything you try to do—even if you’re using a command that should always give a result, such as man -k user. If you get this mes-sage, use the makewhatis command. It can take a few minutes to complete, but once it does, you have a whatis database, and man -k can be used as the invaluable tool that it is.

In Exercise 2.7, you’ll work with man -k to fi nd the information you need about a command.

E X E R C I S E 2 . 7

Working with man -k

1. Open a console, and make sure you are the root.

2. Type makewhatis to create the whatis database. If it already exists, that’s not a problem. makewhatis just creates an updated version in that case.

3. Use man -k as a password. You’ll see a long list of commands that match the keyword password in their description.

c02.indd 64

c02.indd 64 1/8/2013 10:42:27 AM1/8/2013 10:42:27 AM

4. To obtain a more useful result, make an educated guess about which section of the man pages the command you’re looking for is most likely documented in. If you’re looking for a password item, you probably are looking for the command that a user would use to change their password. So, section 1 is appropriate here.

5. Use man -k password | grep 1 to fi lter the result of your man command a bit more.

To fi nish this section about man, there are a few more things of which you should be aware.

There is much interesting information near the end of the man page. In some of the more complicated man pages, this includes examples. There is also a section that lists related commands.

If you still can’t find out how a command works, most man pages list the email address of the person who maintains the page.