The PATH Where Commands Are Searched For

When you type a command at the shell prompt, it has to be read off disk out of one or other directory. On UNIX, all such executable commands are located in one of about four directories. A file is located in the directory tree according to its type, rather than according to what software
package it belongs to. For example, a word processor may have its actual executable stored in a directory with all other executables, while its font files are stored in a directory with other fonts
from all other packages.The shell has a procedure for searching for executables when you type them in. If you type in a command with slashes, like /bin/cp , then the shell tries to run the
named program, cp, out of the /bin directory. If you just type cp on its own,then it tries to find the cp command in each of the subdirectories of your PATH . To see what your PATH is, just type

echo $PATH

You will see a colon separated list of four or more directories. Note that the current directory is not listed. It is important that the current directory not be listed for reasons of security. Hence, to execute a command in the current directory, we hence always ./command .
To append, for example, a new directory /opt/gnome/bin to your PATH , do

export PATH=”$PATH:/opt/gnome/bin”
export PATH

LINUX supports the convenience of doing this in one line:

export PATH=”$PATH:/opt/gnome/bin”

There is a further command, which , to check whether a command is locatable from the PATH . Sometimes there are two commands of the same name in different directories of the PATH . [This is more often true of Solaris systems than LINUX.] Typing which  locates the one
that your shell would execute. Try:
which ls
which cp mv rm
which which
which cranzgots

which is also useful in shell scripts to tell if there is a command at all, and hence check whether a particular package is installed, for example, which netscape.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: