Name

hash — Manage the table of previously found commands.

Synopsis

hash [-dlrt] [-p file] [commands]

As the shell finds commands along the search path ($PATH), it remembers the found locations in an internal hash table. The next time you enter a command, the shell uses the value stored in its hash table.

With no arguments, hash lists the current hashed commands. The display shows hits (the number of times the command has been called by the shell) and the command name. If the table is empty, then if Bash is in POSIX mode, hash prints nothing. Otherwise, it prints hash: hash table empty on standard output.

With commands, the shell adds those commands to the hash table. With no options and just commands, the shell resets the “hit count” associated with each command to zero.

The BASH_CMDS array provides programmatic access to all entries in the hash table; see the section Built-in Shell Variables.

Options

-d

Remove (delete) just the specified commands from the hash table.

-l

Produce output in a format that can be reread to rebuild the hash table.

-p file

Associate file with command in the hash table.

-r

Remove all commands from the hash table.

-t

With one name, print the full pathname of the command. With more than one name, print the name and the full path, in two columns.

Besides the -r option, the hash table is also cleared when PATH is assigned. Use PATH=$PATH to clear the hash table without affecting your search path. This is most useful if you have installed a new version of a command in a directory ...

Get bash Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.