Does bash have a cache to remember where it last found the binary?

Ok, so I play on my system. I copied the GNU word counting program:

cp /usr/bin/wc /usr/bin/wcx

      

and then I ran wc on a text file on my desktop and got the following as expected:

53 79 907 /home/me/Desktop/mytextfile.txt

      

so far nothing unusual. Then I remove (delete) wc

rm /usr/bin/wc

      

and the command returns without terminal output. Therefore, it was removed.

Now at this point I have to note that the PATH in this terminal is:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/bin:/sbin:/bin:/usr/games: [ETC]

      

Now when I run the same command:

wc /home/me/Desktop/mytextfile.txt

      

I'm coming back:

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

      

Now, obviously it won't be able to find the wc binary when I delete it. This is as expected. But curiously, bash seems to have "remembered" where on the PATH it last found the program, since it indicated that it could not find it in / usr / bin

Is this an actual bash specificity? Is there a cache that after it has searched the PATH for a binary once, it knows that it is returning to that location for future requests for that binary?

Thanks for helping clarify this!

+3


source to share


1 answer


Yes, bash has an internal hash table that remembers the full path to previously used commands. Have a look at man bash and find the hash for more details



+5


source







All Articles