Linux中Type命令如何使用

导读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工具用于显示命令的类型信息。它将展示在命令行上输入给定的命令将如何解释。

原文地址:https://www.linuxprobe.com/linux-type-use.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值