Whi*_*uit 18 command-line documentation
假设我能够abc
在命令行中输入并且它会运行(所以 shell 不会说“abc: command not found”)。
我怎样才能知道abc
是什么或做什么?是脚本吗?程序?别名?
ste*_*ver 26
您可以使用type
命令,例如。type abc
. 例如,在 bash shell 中:
$ type while cd ls gcc apt
while is a shell keyword
cd is a shell builtin
ls is aliased to `ls --color=auto'
gcc is /usr/bin/gcc
apt is hashed (/usr/bin/apt)
Run Code Online (Sandbox Code Playgroud)
普通type
命令只显示第一个结果。如果abc
在您的上的不同位置有多个版本PATH
,或者abc
作为 shell 关键字和外部可执行文件提供,或者要查看命令的别名和非别名版本,您可以使用type -a
列出所有这些,例如:
$ type -a time
time is a shell keyword
time is /usr/bin/time
$ type -a ls
ls is aliased to `ls --color=auto'
ls is /bin/ls
$ type -a datamash
datamash is /usr/local/bin/datamash
datamash is /usr/bin/datamash
Run Code Online (Sandbox Code Playgroud)
在 bash 中,type
它本身是一个内置的 shell。其他 shell,例如zsh
andksh
和dash
(/bin/sh
在 Ubuntu 中提供)提供类似的功能(尽管dash
目前不提供type -a
)。在 中tcsh
,最接近的等效项是内置which
命令 - 不要与外部which
命令混淆- 请参阅为什么不使用“which”?那用什么?
对于标识为外部程序的命令(即具有路径,例如/usr/bin/gcc
),您可以使用该file
命令找出程序类型:
$ file /bin/ls /usr/bin/gcc /usr/sbin/adduser
/bin/ls: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=2f15ad836be3339dec0e2e6a3c637e08e48aacbd, for GNU/Linux 3.2.0, stripped
/usr/bin/gcc: symbolic link to gcc-9
/usr/sbin/adduser: Perl script text executable
Run Code Online (Sandbox Code Playgroud)
对于已安装的命令,请使用 steeldriver 的答案。
对于未安装的命令,请阅读以下内容。
有一个名为command-not-found
. 它的目的是
建议在交互式 bash 会话中安装软件包
一旦安装,这个包就会完成它的工作,并建议你安装具有已知可执行名称的 deb-package。
如果您知道可执行文件名称和/或其文件路径的一部分,那么您可以使用以下两个选项之一找到它的包:
当地apt-file
通过
sudo apt-get install apt-file
sudo apt-file update
apt-file search bin/htop
Run Code Online (Sandbox Code Playgroud)
得到类似的东西
Run Code Online (Sandbox Code Playgroud)htop: /usr/bin/htop
使用https://packages.ubuntu.com上的包内容搜索在线- 在此链接中查看结果。