Investigate stale command resolution
Compare the results. Clearing the cache does not install a program or add a PATH directory; if the problem remains, continue checking command search and execution permissions.
A Bash builtin for inspecting and clearing remembered paths to external commands.
type hash
check the command kind
help hash
builtin help
hash
display remembered paths
hash -t ls
show cached ls path, if present
hash -r
clear this shell's table
hash manages Bash's table of remembered external command paths. When finding
a program, the shell does not always need to scan every PATH
directory again. This is local shell state, not a list of installed packages.
The name does not refer to calculating file checksums. The command does not clear DNS, browser caches, or terminal history either. In a lesson about PATH it helps distinguish a saved path from the current search.
Without arguments, hash displays the table. -t prints the path for a
remembered name, -d removes one entry, and -r clears the table. Querying
an entry that has not been created can fail.
Manually binding a name to a path with -p changes command resolution and
requires separate understanding. Inspection and clearing are enough for
ordinary diagnostics. Use help hash for the current shell's documentation.
| Option | What it does | Example |
|---|---|---|
-r |
Reset (clear) the whole table of remembered paths. | hash -r |
-d name |
Remove a single name from the table. | hash -d ls |
-t name |
Print the remembered path for a name. | hash -t ls |
-l |
Print the table in a form that can be reused as input. | hash -l |
-p pathname name |
Explicitly bind a name to a path, skipping the PATH search. dangerous | hash -p /usr/bin/ls ls |
Nothing found. Try a shorter query.
Compare the results. Clearing the cache does not install a program or add a PATH directory; if the problem remains, continue checking command search and execution permissions.
The first call remembers the discovered path, the second displays it, and the third removes the entry. The program file remains in place.
Clear the cache in the shell where the problem occurs. Running bash -c 'hash
-r' separately clears a child shell's table and does not alter its parent.
The name may identify a function or alias. Check type -a ls: an external
path table does not describe every form of Bash name resolution.
This is valid, for example after clearing it. Inspect type ls and shell
settings. An empty cache alone does not mean external programs are missing.
Another shell has its own context. Repeat the observation where the failure occurs instead of editing system files at random.
hash -r deletes neither programs nor user data. It is also not a universal
fix for command not found: an incorrect PATH, a typo, and a missing file
require their own fixes.
Do not manually bind a name to an unverified executable. Changing how a familiar name resolves can cause different code to run with your privileges.
Found an inaccuracy? Report an error in the article