为什么Ubuntu需要这么长时间才能说“找不到命令”


24

由于某种原因,在我的设置中,当我不小心键入命令时,Ubuntu可能需要几秒钟的时间才能响应“找不到命令”。为什么要花这么长时间?有什么方法可以缩短我必须等待的时间吗?

我的PATH中确实有13个目录,但是即使如此(大多数文件中只有几个文件),也不需要花费几秒钟的时间就可以在13个目录中搜索命令了吗?

Answers:


34

外壳不仅可以查看$PATH。如果未找到命令,command_not_found_handle则执行bash函数,然后依次调用python脚本/usr/lib/command-not-found。这会在程序包列表中搜索应安装的程序,此命令才能正常运行。如果您知道拼写错误,只需按Ctrl+ C即可中止搜索过程。

拼写错误的有用消息示例:

$ aptget update
No command 'aptget' found, did you mean:
 Command 'apt-get' from package 'apt' (main)
aptget: command not found

缺少包的有用消息示例:

$ deja-dup
The program 'deja-dup' is currently not installed.  You can install it by typing:
sudo apt-get install deja-dup

另请参阅其背后的原理,https://wiki.ubuntu.com/CommandNotFoundMagic



我认为这是一个真正令人惊奇的功能!如果您使用的命令预期会存在但不存在,则会直接提示您键入要安装的命令。
托尔比约恩Ravn的安徒生

8

这是因为有一个名为“ command-not-found”的软件包。您可以卸载它以缩短响应时间。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.