【每天一个Linux命令】07. Linux中type命令的用法

 

用途说明

type命令用来显示指定命令的类型。一个命令的类型可以是如下几种:

  • alias 别名
  • keyword 关键字,Shell保留字
  • function 函数,Shell函数
  • builtin 内建命令,Shell内建命令
  • file 文件,磁盘文件,外部命令
  • unfound 没有找到

它是Linux系统的一种自省机制,知道了是哪种类型,我们就可以针对性的获取帮助。比如:

内建命令可以用help命令来获取帮助,外部命令用man或者info来获取帮助。

 

常用参数

type命令的基本使用方式就是直接跟上命令名字。

type -a可以显示所有可能的类型,比如有些命令如pwd是shell内建命令,也可以是外部命令。

type -p只返回外部命令的信息,相当于which命令。

type -f只返回shell函数的信息。

type -t 只返回指定类型的信息。

 

举个栗子

常用参数举例:

 

01#1. 显示所有可能的类型
02bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a time
03time is a shell keyword
04time is /usr/bin/time
05#2. 返回外部命令的信息,相当于which
06bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -p time
07#3. 只返回shell函数信息
08bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -f time
09time is a shell keyword
10#4. 只返回指定的类型
11bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -t time
12keyword

 

备注:

 

上面time命令的类型有两个,一个是shell保留字,一个是外部命令,那我们查看帮助的方式可以是

 

 

01bixiaopeng@bixiaopengtekiMacBook-Pro androidshell$ man time
02  
03NAME
04     time -- time command execution
05 
06SYNOPSIS
07     time [-lp] utility
08 
09DESCRIPTION
10     The time utility executes and times utility.  After the utility finishes,
11     time writes the total time elapsed, the time consumed by system overhead,
12     and the time used to execute utility to the standard error stream.  Times
13     are reported in seconds.
14 
15     Available options:
16 
17 
18ile: *manpages*,  Node: time,  Up: (dir)
19 
20 
21bixiaopeng@bixiaopengtekiMacBook-Pro androidshell$ info time
22 
23TIME(1)                   BSD General Commands Manual                  TIME(1)
24 
25NAME
26     time -- time command execution
27 
28SYNOPSIS
29     time [-lp] utility
30 
31DESCRIPTION
32     The time utility executes and times utility.  After the utility finishes,
33     time writes the total time elapsed, the time consumed by system overhead,
34     and the time used to execute utility to the standard error stream.  Times
35-----Info:(*manpages*)time,53 行 --Top-------------------------------------
36欢迎使用 Info 4.8 版。输入 ? 以获得帮助,m 将得到菜单。

 

常用命令举例:

 

 

01bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a ls
02ls is /bin/ls
03bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a who
04who is /usr/bin/who
05bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a cd
06cd is a shell builtin
07cd is /usr/bin/cd
08bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a which
09which is /usr/bin/which
10bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a mvn
11mvn is /usr/share/java/maven-3.0.3/bin/mvn
12mvn is /usr/bin/mvn
13bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a adb
14adb is /Users/bixiaopeng/DevelopSoft/adt-bundle-mac/sdk/platform-tools/adb
15bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a aapt
16aapt is /usr/local/bin/aapt
17 
18bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type grep
19grep is aliased to `grep --color=always'
20bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type awk
21awk is /usr/bin/awk 

订阅

微信搜索“毕小烦”或者扫描下面的二维码,即可订阅我的文章。

image.png

如果文章对你有帮助,请随手点个赞吧!

(完)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

毕小烦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值