我最近在Arch系统上安装了PyQt4和PyQt5,但是当我在终端中运行“qmlviewer”时,它返回:
qmlviewer: could not exec '/usr/lib/qt/bin/qmlviewer': No such file.
我知道我有qmlviewer - locate
返回几个我有qmlviewer的目录。它只是不在我的终端执行的目录中。如何让我的终端尝试从它实际存在的目录中执行qmlviewer?
答案 0 :(得分:1)
bash
会跟踪命令的位置。 (否则它必须每次都搜索PATH 。)当可执行文件移动时,如升级期间可能发生的那样,shell将不知道其路径信息已过期。解决方案是运行hash -r
,它清除shell的路径位置内存。下次您尝试运行可执行文件时,bash
将从头开始搜索PATH以找到它。
这将在实际中进行一些演示。让我们创建一个名为cmd1
的新命令:
# cp /bin/date /bin/cmd1
# cmd1
Tue Mar 18 22:27:23 PDT 2014
bash
必须搜索PATH才能找到cmd1
但是,一旦完成,就会记住,type
命令显示:
# type cmd1
cmd1 is hashed (/bin/cmd1)
现在,让我们通过移动命令来欺骗bash
:
# mv /bin/cmd1 /usr/bin/cmd1
# cmd1
bash: /bin/cmd1: No such file or directory
以下是解决方案:
# hash -r
# cmd1
Tue Mar 18 22:28:20 PDT 2014
# type cmd1
cmd1 is hashed (/usr/bin/cmd1)
man bash
的相关部分是:
hash -rv command ... The shell maintains a hash table which remembers the loca‐ tions of commands. With no arguments whatsoever, the hash command prints out the contents of this table. Entries which have not been looked at since the last cd command are marked with an asterisk; it is possible for these entries to be invalid. With arguments, the hash command removes the specified commands from the hash table (unless they are functions) and then locates them. With the -v option, hash prints the locations of the commands as it finds them. The -r option causes the hash command to delete all the entries in the hash table except for functions.
POSIX中包含hash
功能稍微不那么强大的版本。