Sep*_*ram 8 package-management command-line bash auto-completion
当命令名写错时,bash 经常这样做:
septi@norbert:~$ good
No command 'good' found, did you mean:
Command 'gold' from package 'binutils' (main)
Command 'gmod' from package 'gmod' (universe)
Command 'goo' from package 'goo' (universe)
Command 'god' from package 'god' (universe)
Command 'geod' from package 'proj-bin' (universe)
Command 'gord' from package 'scotch' (universe)
good: command not found
Run Code Online (Sandbox Code Playgroud)
或者有时它会这样做:
septi@norbert:~$ nftp
No command 'nftp' found, but there are 23 similar ones
nftp: command not found
Run Code Online (Sandbox Code Playgroud)
有什么办法可以让 bash 为我显示这 23 个类似的命令吗?并且,有没有办法显示类似的命令,包括那些尚未安装的命令,而不是运行应用程序,ftp例如?
Bash 使用该命令/usr/lib/command-not-found来查找类似的命令。这反过来使用 Python 的CommandNotFound模块。
您在终端上看到的输出(stderr在本例中)也是由此模块生成的。此模块的位置是/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py,在 Ubuntu 14.04 及更高版本上。CommandNotFound.print_spelling_suggestion(self, word, min_len=3, max_len=15)在第 138 行的函数中对类似命令的数量设置了默认限制。您可以将该max_len值修改为30(使用sudo nano或gksudo gedit编辑此文件)。