Bash hash builtin command

Updated: 02/27/2019 by Computer Hope

About hash

The "path hash" is a hash table maintained by bash which contains the remembered locations of executable programs. For instance, when you run the command rsync, bash looks in the hash table to know that it's located at /usr/bin/rsync. This location was determined by searching the paths in your PATH environment variable when the shell was launched.

The hash table is maintained automatically, but you may have a reason to re-calculate the program locations. If so, use the hash command.


hash [-l] [-r] [-p pathname] [-d] [-t] [commandname ... ]

Determine and remember the full pathname of each commandname. If no arguments are given, display information about remembered command locations.


-d Forget the remembered location of each commandname.
-l Display information in a format that can be used as input for another program.
-p pathname Use pathname as the full path of commandname.
-r Forget all remembered locations.
-t Print the remembered location of each commandname. If multiple commandnames are given, precede each location with corresponding commandname.
commandname Each commandname specified is searched for in the PATH environment variable, and if found, is added to the list of remembered commands.

Exit status

The hash command returns 0 for success. Any other value indicates commandname not found, or invalid option given.



Display information about the hash table. If there is no pertinent information, this command displays nothing.

hash -r

Forget all remembered locations, and determine them right now. If you run a command and bash can't find it (because you made a change to your system, for example), run hash -r and try the command again.

hash -d which

Forget the remembered location of the which executable (typically /usr/bin/which) and determine it right now.

hash -t which

Print the remembered location of the which command.


alias — Define aliases (alternative names) for commands.
which — Determine the location of the program associated with a given command.