Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Under what circumstances is the PATH rehashed in bash? I can't figure out when it's necessary to call hash -r and when it happens automatically. The best I can figure out is that the PATH is rehashed whenever a command is typed that isn't found.

share|improve this question
up vote 3 down vote accepted

bash does not hash all contents of PATH. It only has a hashtable of commands that were used during this session (aka in this shell process). For example:

$ hash
hits    command
   1    /home/grawity/code/bin/todo
$ ls
boot/ dev/ etc/ home/ usr/ ...
$ hash
hits    command
   1    /usr/bin/ls
   1    /home/grawity/code/bin/todo

So hash -r is only necessary if you used a program at least once in the current shell, and later moved it elsewhere.

share|improve this answer
OK, that clarifies things a bit, though I still don't get when rehashing happens automatically. – asmeurer Mar 11 '14 at 0:51
@asmeurer: as far as I know, bash never automatically rehashes unless shell option checkhash is set and the hashed filename no longer exists. (And then it only rehashes the one name, not the whole hash.) – rici Mar 11 '14 at 1:29
I see now. So hash -r doesn't rehash, it just clears the hash. – asmeurer Mar 11 '14 at 19:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.