• 本页内容

53. type


从命令行执行的命令可以是别名、shell 内置命令、shell 关键字或外部程序。使用type命令来识别特定命令的类型。

以下示例显示ls是别名,pwd是内置程序,if是 shell 关键字,file是外部程序。

$ type ls
ls is aliased to `ls --color=auto'

$ type pwd
pwd is a shell builtin

$ type if
if is a shell keyword

$ type file
file is /usr/bin/file

如果某个命令既可作为内置程序又可作为外部程序使用,并且您想同时查看这两个命令,则可以使用type -a,如下所示。

$ type -a pwd
pwd is a shell builtin
pwd is /bin/pwd

$ type -a ls
ls is aliased to `ls --color=auto'
ls is /bin/ls