赞
踩
type命令用来显示指定命令的类型。一个命令的类型可以是如下几种:
它是Linux系统的一种自省机制,知道了是哪种类型,我们就可以针对性的获取帮助。比如:
内建命令可以用help命令来获取帮助,外部命令用man或者info来获取帮助。
type命令的基本使用方式就是直接跟上命令名字。
type -a可以显示所有可能的类型,比如有些命令如pwd是shell内建命令,也可以是外部命令。
type -p只返回外部命令的信息,相当于which命令。
type -f只返回shell函数的信息。
type -t 只返回指定类型的信息。
01 | #1. 显示所有可能的类型 |
02 | bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a time |
03 | time is a shell keyword |
04 | time is /usr/bin/time |
05 | #2. 返回外部命令的信息,相当于which |
06 | bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -p time |
07 | #3. 只返回shell函数信息 |
08 | bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -f time |
09 | time is a shell keyword |
10 | #4. 只返回指定的类型 |
11 | bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -t time |
12 | keyword |
备注:
上面time命令的类型有两个,一个是shell保留字,一个是外部命令,那我们查看帮助的方式可以是
01 | bixiaopeng@bixiaopengtekiMacBook-Pro androidshell$ man time |
02 | |
03 | NAME |
04 | time -- time command execution |
05 |
06 | SYNOPSIS |
07 | time [-lp] utility |
08 |
09 | DESCRIPTION |
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 |
18 | ile: *manpages*, Node: time , Up: ( dir ) |
19 |
20 |
21 | bixiaopeng@bixiaopengtekiMacBook-Pro androidshell$ info time |
22 |
23 | TIME(1) BSD General Commands Manual TIME(1) |
24 |
25 | NAME |
26 | time -- time command execution |
27 |
28 | SYNOPSIS |
29 | time [-lp] utility |
30 |
31 | DESCRIPTION |
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 将得到菜单。 |
01 | bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a ls |
02 | ls is /bin/ls |
03 | bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a who |
04 | who is /usr/bin/who |
05 | bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a cd |
06 | cd is a shell builtin |
07 | cd is /usr/bin/cd |
08 | bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a which |
09 | which is /usr/bin/which |
10 | bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a mvn |
11 | mvn is /usr/share/java/maven-3 .0.3 /bin/mvn |
12 | mvn is /usr/bin/mvn |
13 | bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a adb |
14 | adb is /Users/bixiaopeng/DevelopSoft/adt-bundle-mac/sdk/platform-tools/adb |
15 | bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a aapt |
16 | aapt is /usr/local/bin/aapt |
17 |
18 | bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type grep |
19 | grep is aliased to ` grep --color=always' |
20 | bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type awk |
21 | awk is /usr/bin/awk |
微信搜索“毕小烦”或者扫描下面的二维码,即可订阅我的文章。
如果文章对你有帮助,请随手点个赞吧!
(完)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。