Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

After I move an executable file which I've recently executed (or more commonly, after I uninstall something from somewhere and install a different version somewhere else), bash can't find it, even if it's still on the PATH.

Example:

find
sudo mv /usr/bin/find /usr/local/bin
find

Results in:

bash: /usr/bin/find: No such file or directory

This is really annoying because it's happened to me dozens of times. How can I stop this happening?

share|improve this question
    
Which file, where was it, where is it now, what permissions does it have, what command did you use to move it, what is your current $PATH. Please provide significantly more detail. –  EightBitTony May 27 '12 at 11:35
add comment

3 Answers

To clear the immediate problem:

hash -r

To stop it happening again:

set +h

to disable hashing (i.e. in-memory caching).

This can be put in a bash startup file such as /etc/bashrc.

The downside of this solution is that it slows things down a little if you have slow network filesystem(s) mounted and on the PATH.

Really, in my opinion, this is an ancient bash bug which should have been fixed years ago, and this is just a workaround.

share|improve this answer
add comment

This can happen if the new copy isn't executable, so have a look at its permissions and ensure they're correct.

share|improve this answer
add comment
up vote 1 down vote accepted

To fix the problem permanently without disabling hashing entirely, put this in your bashrc:

shopt -s checkhash

See my other answer for how to solve the immediate problem.

share|improve this answer
add comment

Your Answer

 
discard

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.