|Lesson 7||Search paths and commands|
|Objective|| Determine where a command is located and modify the search path to use the
Search paths | Commands
Almost all UNIX commands are executable programs, and invoking a command in a shell almost always means running that executable program.
Therefore, all the concepts we have discussed regarding file permissions and process ownership apply to commands. You should remember a few additional ideas when working with interactive commands.
As you know, when a command name is typed to a shell, the shell uses its search path to locate the corresponding executable file. The
search path is set in the system-wide login file (usually /etc/login or /etc/profile) by the use of the
environment variable. Users may modify the search path in their personal login scripts.
The simplest way to view the search path is
This command displays the default search path of the current shell. Notice that you must use
$ in front of
PATH. This is standard when referring to environment variables in commands.
The search path can be modified in the following way:
The first line adds the directory /usr/sbin to the end of the search path as defined in the
PATH environment variable. The
second line makes this change global by exporting the path to the system-wide environment variable.
Many of the administrative commands are located in /sbin and /usr/sbin, and these directories are not typically included in the search
path. When working as an administrator, you may find it convenient to modify your personal search path to include these directories.
Otherwise, you will need to give full pathnames to many administrative commands.
Same name, different paths
Confusion can occur when several commands with the same name are located in different parts of the filesystem. For example, some versions of UNIX supply two versions of
common commands, one of which takes the BSD family of options, and the other which takes the System V family of options. The BSD-like commands might be in /usr/ucb/bin, whereas the System V commands stay in /usr/bin. Which command gets run when you type, for example,
which command is a handy way to tell:
$ which stty
We have also seen the useful
whereis command, which tells us which file gets executed, as well as where the source and manual pages for a particular command are located.
$ whereis stty
Search-paths - Exercise
Click the Exercise link to practice your knowledge of search paths and commands.
Search-paths - Exercise
environment variable: An environment variable is a system variable that contains information about some aspect of the system's environment. For example, the PATH environment variable describes the search path that is used whenever a command name is entered without an explicit directory location.
filesystem: A UNIX filesystem is a directory hierarchy. A UNIX system has one overall filesystem, with its root at /, which may be made up of a number of other filesystems.
BSD: BSD is a type of UNIX operating system derived from the work done at Computer Science laboratories at the University of California at Berkeley. The most commonly encountered BSD system is SunOS version 4.3. Berkeley's BSD version 4.4 is also fairly common.