Utilities

Once the shell has processed all of its special characters, what remains typically consists of commands and the arguments to them. Most commands correspond to executable files somewhere on your system, although some—such as cd—are built into the shell.

It's possible for you to have more than one executable file with the same name on your system. The shell uses the PATH environment variable to determine which version to use.

The value of PATH is a list of directories, separated by colons (:), in the order in which you want the shell to search for executables. To see the value of your PATH, type:

echo $PATH

You can put your current directory (.) in your PATH, but it can leave you vulnerable to "Trojan horse" programs. For example, if . is at the beginning of your PATH, the shell looks in the current directory first when trying to find a program. A malicious user could leave a program called ls in a directory as a trap for you to fall into.

If you want to have your current directory in your PATH, make sure that you put it after the directories that hold the common utilities.

If you want to know which version of a command the shell will choose, use the which command. For example:

$ which ls
/bin/ls

You can use command-line options to get more information:

$ which -laf ls
-rwxrwxr-x  1 root      root         19272 May 03  2002 /bin/ls

If you try this for a command that's built into the shell, which can't find it:

$ which cd
which: no cd in /bin:/usr/bin:/opt/bin

The whence command displays what the command means to the shell, including any aliases in effect. For example, if you've created an alias for ls, the output might be:

$ whence ls
'ls -F'

Last modified: 2013-12-21

comments powered by Disqus