The shell uses your search path ($PATH) to define the list of directories to search whenever you type a command. See Chapter 3, “Solaris Shells and Variables,” for a description of the $PATH variable. If the command is not found in the search path, you will receive an error similar to this one:
ksh: lpsched: not found
In this case, I typed the lpsched command, and the system responded by telling me the command was not found. I know the command exists; I just don’t have the path defined in my PATH variable. To find the path to a command, use one of the following commands:
Command | Description |
---|---|
whereis <command> | Locates the binary, source, and manual page files for a command. |
which <command> | Locates a command and displays its pathname or alias. |
whence | whence is used to show the absolute pathname of a command. whence is a shell built-in and is only available in the Korn shell. |
Note
The whereis command is actually an old BSD command and is located in the /usr/ucb/ directory with all of the other old BSD commands. If the root user does not have /usr/ucb in its search path, you might get the whereis: not found message when running this command as root.
Example 1:
To find the location of the lpsched command, I’ll use the whereis command as follows:
whereis lpsched <cr>
The system displays the following information about the lpsched command:
lpsched: /usr/lib/lpsched
Example 2:
The which command will only search the directories specified in my search path to locate the file. In this example, I’m logged in as a regular nonroot user. I’ll use the which command to look for the command named lpsched in my current search path:
which lpsched <cr>
The system displays the following information about the lpsched command:
no lpsched in /usr/bin /usr/ucb /etc .
Example 3:
The whence command displays the absolute pathname of a command. When used with the –v option, I can display information about any command or reserved word that is used in the Korn shell, as follows:
whence if <cr>
The system displays the following information:
if is a reserved shell keyword