良许Linux教程网 Linux命令大全 Linux中Type命令如何使用

Linux中Type命令如何使用

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

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

type [-afptP] [name ...]

例如,查看type的类型:

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

也可以提供多个参数:

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

命令的类型

-t选项告诉type打印一个描述命令类型的单词,该单词会是下面其中之一:

  • alias – 别名

  • builtin – 内置命令

  • file – 文件

  • keyword – 关键字

这里有一些例子:

Alias

[root@localhost ~]# type -t lsalias# 在Centos系统中,ls别名对应的命令是ls --color=auto[root@localhost bin]# type lsls is aliased to `ls --color=auto'

Builtin

[root@localhost ~]# type -t printfbuiltin

printf是shell内置的命令

File

[root@localhost ~]# type -t awkfile

awk是可执行的文件

Keyword

[root@localhost ~]# type -t whilekeyword

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

显示命令的位置和类型

使用-a命令可以显示命令的位置和类型:

[root@localhost ~]# type -a ls printf awk whilels is aliased to `ls --color=auto'ls is /usr/bin/lsprintf is a shell builtinprintf is /usr/bin/printfawk is /usr/bin/awkwhile is a shell keyword

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

以上就是良许教程网为各位朋友分享的Linux中Type命令如何使用。想要了解更多Linux相关知识记得关注公众号“良许Linux”,或扫描下方二维码进行关注,更多干货等着你!
公众号

本文由 良许Linux教程网 发布,可自由转载、引用,但需署名作者且注明文章出处。如转载至微信公众号,请在文末添加作者公众号二维码。
良许

作者: 良许

良许,世界500强企业Linux开发工程师,公众号【良许Linux】的作者,全网拥有超30W粉丝。个人标签:创业者,CSDN学院讲师,副业达人,流量玩家,摄影爱好者。
上一篇
下一篇

发表评论

联系我们

联系我们

公众号:良许Linux

在线咨询: QQ交谈

邮箱: yychuyu@163.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部