0
点赞
收藏
分享

微信扫一扫

Linux “Commnad not found“和“no such file or directory“的区别

米小格儿 2022-04-06 阅读 151
linux

使用linux时,对于不能执行的命令,有时显示"Commnad not found",有时显示"no such file or directory"。

举例如下:

yc@ubuntu:/usr/bin$ kd  (kd是随便输入的命令)
kd: command not found

yc@ubuntu:/usr/bin$ qmake  (qmake命令)
bash: /usr/bin/qmake: No such file or directory


以上两种情况都无法执行命令,但是错误提示确不一样。

使用type查看

yc@ubuntu:/usr/bin$ type kd
bash: type: kd: not found
 

yc@ubuntu:/usr/bin$ type qmake
qmake is hashed (/usr/bin/qmake)

注意看type qmake的返回信息,其中有hashed关键字样

这是因为bash会记住命令位置,并将其存入hash表中。

不管什么原因(卸载,删除,或者其他)qmake失效,hash 表记录并没有被清除,仍然认为qmake还在(/usr/bin/qmake)。bash认为qmake仍然有效,所以跳过PATH查找,直接调用/usr/bin/qmake,所以返回No such file or directory 

使用hash -d移除错误记录

yc@ubuntu:/usr/bin$ hash -d qmake


然后重新执行qmake

yc@ubuntu:/usr/bin$ qmake
The program 'qmake' is currently not installed. You can install it by typing:
sudo apt-get install qtchooser
 

这次没有在显示No such file or directory。由于qmake可以被安装,所以出现安装方法提示。

附:移除整个hash表

hash -r

举报

相关推荐

0 条评论