The bash
shell provides a help
command that will give information about all its built-in commands. Example 4-13 shows how to get information about the alias
command.
Example 4-13. Getting help for alias
$ help alias
alias: alias [-p] [name[=value] ... ]
'alias' with no arguments or with the -p option prints the list
of aliases in the form alias NAME=VALUE on standard output.
Otherwise, an alias is defined for each NAME whose VALUE is given.
A trailing space in VALUE causes the next word to be checked for
alias substitution when the alias is expanded. Alias returns
true unless a NAME is given for which no alias has been defined.
If you want to get a list of commands that help
can help you with, use the command by itself.
To get help about any other command in the Unix shell, use man
, the all-purpose, Swiss Army knife for getting information for most commands on the system in a form known as a manpage
. For example, to see the manpage for man
, type the following:
$ man man
When you execute this command, you’ll see the output shown in Figure 4-4. Notice that there’s a colon (:
) at the bottom of the window with the cursor next to it. This indicates that there’s more content to be seen in the manpage. At the prompt, you can:
Hit the spacebar or the F key to page down.
Hit the B key to go back a page.
Type a / (slash) followed by a word to search forward for that word.
Hit the Q key to quit.
When you quit out of viewing a manpage, the information goes away and you are left with the same contents in your window as you had before you executed the man
command. This is because man
actually uses the program configured in your environment to be the pager—a program that can take output and step through it a page at a time. By default, the pager is the less
tool, which is the application that allows you to use the keystrokes listed above. If you want, you can use the more
pager by setting your PAGER
environment variable as follows:
$ export PAGER=more
The more
pager isn’t as full-featured as less
, but it does leave the contents of the manpage onscreen when you exit. All things being equal though, I suggest you open
a second Terminal window rather than change your pager to browse the manpage documentation.
The real trick to using man
is knowing which command might be the one that you want information on. To help you find the right manpage, use the apropos
command. For example, if you want to find the manpages containing information about power management, use the following command:
$ apropos power
This returns six manpages, with one for pmset
that has a summary indicating that it’s for modifying power management settings.
Of course, there are other resources for helping you out with the command line. In addition to the books listed in the “Further Explorations” section toward the end of this chapter, you can find help online. A good place to start is Google (http://www.google.com). If you’re having trouble with a specific command, enter it into the Google search box and see what comes up. Chances are, one of the first few hits will either have a tutorial or some pointers to get you in the right direction.
O’Reilly’s own Mac DevCenter (http://www.macdevcenter.com) often has tips on using the command line or provides other articles related to Mac OS X’s Unix subsystem. Also, it’s worth remembering that there are very few practical differences between the shell on Mac OS X and on other Unixes. So most articles you find for FreeBSD, Linux, and other Unix flavors will prove helpful as well.