hash Command

Purpose

Remembers or reports command path names.

Syntax

To Add the Path of a Command to the Path Name List
hashCommand ... ]
To Clear Path Name List
hash -r

Description

The hash command affects the way that 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 can also contain those commands that are invoked and found through the normal command search process.

Note: Shell built-in commands are not reported by the hash command.

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.

Flag

Table 1. Flag
Item Description
-r Clears the contents of the path name list.

Parameter

Table 2. Parameter
Item Description
Command Specifies the Command to add to the path name list.

Exit Status

The following exit values are returned:

Table 3. Exit Status
Item Description
0 Successful completion.
>0 An error occurred.

Examples

  1. To find the path name of the wc command and add it to the path name list, enter:
    hash wc
  2. To clear the contents of the path name list, enter:
    hash -r

Files

Table 4. Files
Item Description
/usr/bin/ksh Contains the Korn shell hash built-in command.
/usr/bin/hash Contains the hash command.