简体   繁体   English

bash有缓存来记住上次找到二进制文件的位置吗?

[英]Does bash have a cache to remember where it last found a binary?

Ok, so I am playing around in my system. 好的,所以我在我的系统里玩。 I copied the GNU word count program: 我复制了GNU字数统计程序:

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: 然后我在桌面上的文本文件上运行了wc,并按预期得到了以下内容:

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

so far nothing out of the ordinary. 到目前为止没有什么与众不同的。 I then delete (remove) wc 然后我删除(删除)wc

rm /usr/bin/wc

and the command returns with no terminal output. 并且命令返回时没有终端输出。 So it has been removed. 所以它已被删除。

Now at this point I should note that the PATH in this terminal is: 现在在这一点上我应该注意到这个终端中的PATH是:

/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 get back: 我回来了:

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

Now, obviously it should not be able to find the wc binary as I deleted it. 现在,显然它应该无法找到wc二进制文件,因为我删除它。 That is as expected. 这是预期的。 But the curious thing is that bash appears to have 'remembered' where on the PATH it last found the program as it has indicated that it can't find it in /usr/bin 但奇怪的是,bash似乎已经“记住”它最后发现程序的PATH,因为它表明它无法在/ usr / bin中找到它

Is this an actual feature of bash? 这是bash的实际特征吗? Is there a cache that, once it has searched the PATH for the binary once, it knows to return to that place for future requests of that binary? 是否有一个缓存,一旦它在PATH中搜索二进制文件一次,它就知道返回那个地方以便将来对该二进制文件的请求?

Thanks for helping to clear this up! 感谢您帮忙解决此问题!

Yes bash has an internal hash table that remembers the full path to previously used commands. 是的bash有一个内部哈希表,可以记住以前使用的命令的完整路径。 See man bash and search for hash for further details 请参阅man bash并搜索hash以获取更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM