The path directory order is important. Directories are checked from left to right. So, in this example,
if there is a command called
foo
located in both the
/bin
and
/usr/bin
directories, the one
in
/bin
is executed. To have the other
foo
command run, you either type the full path to the
command or change your PATH variable. (Changing your PATH and adding directories to it are
described later in this chapter.)
Not all the commands that you run are located in directories in your PATH variable. Some com-
mands are built into the shell. Other commands can be overridden by creating aliases that define
any commands and options that you want the command to run. There are also ways of defining a
function that consists of a stored series of commands. Here is the order in which the shell checks
for the commands you type:
1.
Aliases -- Names set by the
alias
command that represent a particular command and a
set of options. (Type alias to see what aliases are set.) Often, aliases enable you to define a
short name for a long, complicated command.
Getting Help Using the Shell
When you first start using the shell, it can be intimidating. All you see is a prompt. How do you
know which commands are available, which options they use, or how to use advanced features?
Fortunately, lots of help is available. Here are some places you can look to supplement what you
learn in this chapter:
Check the PATH -- Type echo $PATH. You see a list of the directories containing com-
mands that are immediately accessible to you. Listing the contents of those directories
displays most standard Linux commands.
Use the
help
command -- Some commands are built into the shell, so they do not
appear in a directory. The
help
command lists those commands and shows options avail-
able with each of them. (Type help | less to page through the list.) For help with a partic-
ular built-in command, type help command, replacing command with the name that
interests you. The
help
command works with the bash shell only.
Use
--help
with the command -- Many commands include a
--help
option that
you can use to get information about how the command is used. For example, type
date --help | less. The output shows not only options, but also time formats you can
use with the date command.
Use the
man
command -- To learn more about a particular command, type man com-
mand. (Replace command with the command name you want.) A description of the com-
mand and its options appears on the screen.
Use the
info
command -- The
info
command is another tool for displaying information
about commands from the shell. The
info
command can move among a hierarchy of
nodes to find information about commands and other items. Not all commands have
information available in the info database, but sometimes more information can be found
there than on a man page.
47
Running Commands from the Shell
2