On Unix-like operating systems, hash is a built-in command of the bash shell that views, resets, or manually changes the bash path hash. The path hash is a hash table, maintained by bash, containing the disk locations where the shell should look for executable programs when a command is run.
Description
When you run a command, bash looks up its location on disk in the hash table. This table of locations was previously determined when the shell was launched, according to the PATH environment variable in the shell’s init script, e.g., .bashrc or .bash_profile.
- Syntax
- Examples
- Related commands
- Bash builtins help
- Linux commands help
The hash table is maintained automatically, but you can force it to re-calculate its program locations with the hash command.
Syntax
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.
Options
Exit status
The hash command returns 0 for success. Any other value indicates commandname not found, or invalid option given.
Examples
hash
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.
/usr/bin/which
Related commands
alias — Define aliases (alternative names) for commands.which — Determine the location of the program associated with a given command.