I already have a pre-installed gcc
in debian, and I also have compiled another gcc successfully, which is installed in /root/tools/
.But after that, I typed type gcc
, it showed gcc is hashed (/bin/gcc)
. What does this mean ?
My bash PATH
variable : PATH=/root/tools/bin:/bin:/usr/bin
2
Answers
hashed means that the shell knows where it is. When you run a command like
gcc
the first time, the shell goes and finds it in the path. The second time, the shell doesn’t go look for it, because the shell has remembered where it is. This is called hashing, probably because it uses a hash table internally.If you want the shell to forget its remembered locations, use the command
rehash
. This is useful if you install a new program somewhere, but the shell won’t find it, because it’s remembering its old location.Edited to add: You can also use
hash -l
to see what the shell has hashed.In the addition to Andy’s answer here is the list of some examples.
They show how bash adds file paths to its hash:
Part II. If you want to see the path to your program i suggest to use "$type -p" :
-p key description:
Sometimes -p key is not enough. -a key will help: