关于linux:Linux系统中Type命令如何使用

3次阅读

共计 929 个字符,预计需要花费 3 分钟才能阅读完成。

type工具用于显示命令的类型信息。它将展现在命令行上输出给定的命令将如何解释。

如何应用 type 命令

type命令是 bash 内置,type 语法:

type [-afptP] [name …]

例如,查看 type 的类型:

[root@localhost ~]# type type
type is a shell builtin

也能够提供多个参数:

[root@localhost ~]# type vim sleep head
vim is hashed (/usr/bin/vim)
sleep is /usr/bin/sleep
head is /usr/bin/head

命令的类型

-t选项通知 type 打印一个形容命令类型的单词,该单词会是上面其中之一:

  • alias – 别名
  • builtin – 内置命令
  • file – 文件
  • keyword – 关键字

这里有一些例子:

Alias

[root@localhost ~]# type -t ls
alias

在 Centos 零碎中,ls 别名对应的命令是ls --color=auto

[root@localhost bin]# type ls
ls is aliased to `ls –color=auto’

Builtin

[root@localhost ~]# type -t printf
builtin

printf 是 shell 内置的命令

File

[root@localhost ~]# type -t awk
file

awk 是可执行的文件

Keyword

[root@localhost ~]# type -t while
keyword

while、for、if、else……等等,是 Bash 中保留的关键字

显示命令的地位和类型

应用 -a 命令能够显示命令的地位和类型:

[root@localhost ~]# type -a ls printf awk while
ls is aliased to `ls –color=auto’
ls is /usr/bin/ls
printf is a shell builtin
printf is /usr/bin/printf
awk is /usr/bin/awk
while is a shell keyword

这个实例执行后显示了 ls,printf,awk,while 命令的类型和地位。

总结

type工具用于显示命令的类型信息。它将展现在命令行上输出给定的命令将如何解释。

正文完
 0