bash命令的路径缓存

时间:2013-10-13 13:12:06

标签: python macos bash

使用ports:

卸载旧版本后,找不到python脚本
 sudo port uninstall --follow-dependents python27

但是python2.7文件位于系统路径中:

➜ ~ $ which python2.7
/usr/bin/python2.7
➜ ~ $ python2.7 -V
-bash: /opt/local/bin/python2.7: No such file or directory
➜ ~ $ ll /opt/local/bin/python*
ls: /opt/local/bin/python*: No such file or directory    
➜ ~ $ ll /usr/bin/python*
-rwxr-xr-x  2 root  wheel    57K 10 12 21:47 /usr/bin/python
-rwxr-xr-x  5 root  wheel   925B 10 12 21:47 /usr/bin/python-config
lrwxr-xr-x  1 root  wheel    75B 10 12 21:47 /usr/bin/python2.5 -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5
lrwxr-xr-x  1 root  wheel    82B 10 12 21:47 /usr/bin/python2.5-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5-config
lrwxr-xr-x  1 root  wheel    75B 10 12 21:47 /usr/bin/python2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
lrwxr-xr-x  1 root  wheel    82B 10 12 21:47 /usr/bin/python2.6-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6-config
lrwxr-xr-x  1 root  wheel    70B 10 13 20:38 /usr/bin/python2.7 -> /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x  1 root  wheel    82B 10 12 21:47 /usr/bin/python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
-rwxr-xr-x  2 root  wheel    57K 10 12 21:47 /usr/bin/pythonw
lrwxr-xr-x  1 root  wheel    76B 10 12 21:47 /usr/bin/pythonw2.5 -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw2.5
lrwxr-xr-x  1 root  wheel    76B 10 12 21:47 /usr/bin/pythonw2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw2.6
lrwxr-xr-x  1 root  wheel    76B 10 12 21:47 /usr/bin/pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
➜ ~ $ /usr/bin/python2.7 -V
Python 2.7.5
➜ ~ $ ll /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
-rwxr-xr-x  1 root  wheel    34K 10 12 21:47 /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7

PATH值是:

➜ ~ $ echo $PATH|tr ':' '\n'
/Users/adyliu/.rvm/gems/ruby-2.0.0-p247/bin
/Users/adyliu/.rvm/gems/ruby-2.0.0-p247@global/bin
/Users/adyliu/.rvm/rubies/ruby-2.0.0-p247/bin
/Users/adyliu/.rvm/bin
/opt/local/bin
/opt/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
/Users/adyliu/bin

之前我使用ports安装了python2.7.3,所以'/ opt / local / bin'的路径在'/ usr / bin'的路径之前, 在我卸载这个python之前,python脚本(python2.7)在'/ opt / local / bin'中。

现在我的问题是为什么虽然文件在系统路径中但找不到python脚本。

➜ ~ $ for d in `echo $PATH|tr ':' ' '`;do if [ -x $d/python2.7 ]; then ls -lh $d/python2.7;fi;done
lrwxr-xr-x  1 root  wheel    70B 10 13 20:38 /usr/bin/python2.7 -> /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
➜ ~ $ which python2.7
/usr/bin/python2.7
➜ ~ $ python2.7 -V
-bash: /opt/local/bin/python2.7: No such file or directory    

如何删除命令的哈希缓存:

➜ ~ $ command -V python2.7
python2.7 is hashed (/opt/local/bin/python2.7)
➜ ~ $ type python2.7
python2.7 is hashed (/usr/bin/python2.7)
➜ ~ $ type python
python is hashed (/usr/bin/python)

更新1

我不知道为什么现在可以找到'python2.7'(问题发布后10分钟)。

➜ ~ $ command -V python2.7
python2.7 is hashed (/usr/bin/python2.7)

更新2

仍无法找到'python2'脚本:

➜ ~ $ python2 -V
-bash: /opt/local/bin/python2: No such file or directory
➜ ~ $ python2
-bash: /opt/local/bin/python2: No such file or directory
➜ ~ $ which python2
/usr/bin/python2
➜ ~ $ command -V python2
python2 is hashed (/opt/local/bin/python2)
➜ ~ $ python2 -V
-bash: /opt/local/bin/python2: No such file or directory
➜ ~ $ /usr/bin/python2 -V
Python 2.7.5
➜ ~ $ ll /usr/bin/python2
lrwxr-xr-x  1 root  wheel    18B 10 13 20:50 /usr/bin/python2 -> /usr/bin/python2.7
➜ ~ $ python2.7 -V
Python 2.7.5
➜ ~ $ python2 -V
-bash: /opt/local/bin/python2: No such file or directory

1 个答案:

答案 0 :(得分:0)

首先检查文件的大小:

du -sh /usr/bin/python2

可能是文件不在那里。