Remembers or reports command path names.
To Add the Path of a Command to the Path Name List:
hash [ Command ... ]
To Clear Path Name List:
hash -r
The hash command affects the way the current shell remembers a command's path name, either by adding a path name to a list or purging the contents of the list.
When no parameter or flag is specified, the hash command reports to standard output the contents of the path name list. The report includes the path name of commands in the current shell environment that were found by previous hash command invocations. The display may also contain those commands invoked and found through the normal command search process.
You can use the -r flag to clear the contents of the command path name list. Path names can also be cleared from the list by resetting the value of the PATH environment variable. In the simplest form, this would be achieved by entering:
PATH="$PATH"
If the Command parameter is used, the hash command searches for the path name of the specified command and adds this path to the list. Do not use a / (slash) when you specify the command.
Since the hash command affects the current shell environment, it is provided as a Korn shell or POSIX shell regular built-in command. If the hash command is called in a separate command execution environment, as in the following examples, it will not affect the command search process of the caller's environment:
nohup hash -r
find . -type f | xargs hash
Using the hash command is equivalent to using the alias -t command.
Item | Description |
---|---|
-r | Clears the contents of the path name list. |
Item | Description |
---|---|
Command | Specifies the Command to add to the path name list. |
The following exit values are returned:
Item | Description |
---|---|
0 | Successful completion. |
>0 | An error occurred. |
hash wc
hash -r
Item | Description |
---|---|
/usr/bin/ksh | Contains the Korn shell hash built-in command. |
/usr/bin/hash | Contains the hash command. |