The commands you can type in the shell are almost always the names of executable programs elsewhere in the system. Some shell commands are internal and specific to each particular shell (such as alias), but most commands must correspond to some installed program. The trick in using the shell efficiently is knowing which of these programs does what. That's where the built-in "manual" comes in. The manual is invoked using the man command, and you can find information on any known command or program like so: # man ls This would give you a full, browseable set of documentation on the ls ("list") command and all its available options. The same method will get you information and syntax for any installed program, whether it came with FreeBSD or was installed after the fact. You can use the spacebar, the arrow keys, and the Page Up/Page Down keys to review the contents of the manual page, or press / and enter a text string to search for that string. Press Q to exit the manual. Searching for Manual PagesSometimes, you might know what you want to do, but you are not sure of the name of the command to use. In this case, you can use the -k option to the man command to specify a general concept and return a list of possible commands that might help execute it. Sometimes, you have to be fairly creative about what you search for in order for man -k to return the results you want. For example, suppose you want to find out about commands that can search text files for certain words or phrases, and you want to show each place in the text file where a certain word or phrase occurs. You would likely assume that such commands would have "search" in their names or their descriptions. First, you might try the man -k search command, as shown in Listing 8.1. The output of this command is a list of all the relevant entries in the whatis database, a dictionary of programs and their descriptions. (The output on your system may be different depending on what software you have installed.) Listing 8.1. Using man -k
This probably isn't what you had in mind. The results seem to be geared toward search routines for programmers using C. For your next attempt, you try searching for the keyword pattern, as shown in Listing 8.2, because you want a command that finds patterns in text files. Listing 8.2. Another Attempt with man -k
Now that looks more usefulespecially the grep series of commands. These seem to be tools for searching for patterns within files, as you hoped. You could now type man grep to read the man page for grep, and you would find that indeed this command does what you need. Command SummariesAt other times, you might know the name of a command but are not sure what it does (if you are poking around in /usr/bin or /usr/games, for example). You can use the -f option to man to get a short, one-line description of a command. For example, suppose you find the command pom in the /usr/games directory, and you want to know what it does: # man -f pom pom(6) - display the phase of the moon The (6) at the end of the command name is the section of the manual that the command comes from. Manual SectionsThe online manuals are divided into nine sections, as detailed in Table 8.1.
Some commands have more than one entry. For example, the crontab enTRy has an entry in Section 1 for the crontab command and also an entry in Section 5 for the format of the crontab file. If you don't specify a manual section when you use the man command, you'll get the first entry in the manual that matches what you're looking forin the case of man crontab, this means that you get the entry listed in Section 1, describing the command syntax. If you want to see the entry on file formats in Section 5, use man 5 crontab. |