Reputation: 2346
I have a "gtags" executable in /usr/bin, but this is an older one. Then I've compiled a new gtags and "make install" puts it in /usr/local/bin. then I removed the one in /usr/bin. But when I typed "gtags" in shell, it told me that "/usr/bin/gtags" cannot found. But I have a "gtags" in /usr/local/bin, and the /usr/local/bin is in the PATH. Also, in my PATH, the /usr/local/bin is searched before /usr/bin, why the shell only checked "gtags" in /usr/bin?
Upvotes: 1
Views: 708
Reputation: 7455
Use the bash built-in command hash
:
[root@localhost ~]# touch /bin/test.sh
[root@localhost ~]# chmod 755 /bin/test.sh
[root@localhost ~]# test.sh
[root@localhost ~]# mv /bin/test.sh /usr/local/bin/
[root@localhost ~]# test.sh
-bash: /bin/test.sh: No such file or directory
[root@localhost ~]# hash test.sh
[root@localhost ~]# test.sh
The reason this happens is bash "caches" where the binary is in $PATH so it doesn't have to find it each time it wants to run it. It's a performance thing. If you run "hash" with no arguments it'll report which commands its ran, how many times, and where it ran it from.
Upvotes: 3