4.10. What Is a Command?
We've said that Unix offers a huge number of commands and that you can add new ones. This makes it
This makes Unix very flexible and powerful. To provide a new utility, a system administrator can simply install it in a standard directory where commands are located. There can also be different versions of a commandfor instance, you can offer a new version of a utility for testing in one place while leaving the old version in another place, and users can choose the one they want.
Here's a common problem: sometimes you enter a command that you expect to be on the system, but you receive a message such as "Not found." The problem may be that the command is located in a directory that your shell is not searching. The list of directories where your shell looks for commands is called your
$ echo $PATH /usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/lib/java/bin:\ /usr/games:/usr/bin/TeX:.
This takes a little careful eyeballing. First, the word
is specially recognized by the shell and is called an
. It's a short moniker for useful informationin this case, a list of directories where the shell should search for commands. There are lots of environment
The output of our
command is a series of pathnames separated by colons. The first pathname, for this particular
If a command is not found, you have to figure out where it is on the system and add that directory to your path. The manual page should tell you where it is. Let's say you find it in /usr/sbin , where a number of system administration commands are installed. You realize you need access to these system administration commands, so you enter the following (note that the first PATH doesn't have a dollar sign, but the second one does):
$ export PATH=$PATH:/usr/sbin
This command adds /usr/sbin , but makes it the last directory that is searched. The command is saying, "Make my path equal to the old path plus /usr/sbin ."
The previous command works for some shells but not others. It's fine for most Linux users who are working in a Bourne-compatible shell like bash . But if you use csh or tcsh , you need to issue the following command instead:
set path = ( $PATH /usr/sbin )
Finally, there are a few commands that are not files;
is one. Most of these commands affect the shell itself and therefore have to be