用途說明
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 隻傳回指定類型的資訊。
舉個栗子
常用參數舉例:
02 | [email protected] ~$ type -a time |
03 | time is a shell keyword |
05 | #2. 傳回外部指令的資訊,相當于which |
06 | [email protected] ~$ type -p time |
08 | [email protected] ~$ type -f time |
09 | time is a shell keyword |
11 | [email protected] ~$ type -t time |
備注:
上面time指令的類型有兩個,一個是shell保留字,一個是外部指令,那我們檢視幫助的方式可以是
01 | [email protected] androidshell$ man time |
04 | time -- time command execution |
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. |
18 | ile: *manpages*, Node: time , Up: ( dir ) |
21 | [email protected] androidshell$ info time |
23 | TIME(1) BSD General Commands Manual TIME(1) |
26 | time -- time command execution |
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 | [email protected] ~$ type -a ls |
03 | [email protected] ~$ type -a who |
05 | [email protected] ~$ type -a cd |
08 | [email protected] ~$ type -a which |
09 | which is /usr/bin/which |
10 | [email protected] ~$ type -a mvn |
11 | mvn is /usr/share/java/maven-3 .0.3 /bin/mvn |
13 | [email protected] ~$ type -a adb |
14 | adb is /Users/bixiaopeng/DevelopSoft/adt-bundle-mac/sdk/platform-tools/adb |
15 | [email protected] ~$ type -a aapt |
16 | aapt is /usr/local/bin/aapt |
18 | [email protected] ~$ type grep |
19 | grep is aliased to ` grep --color=always' |
20 | [email protected] ~$ type awk |
訂閱
微信搜尋“畢小煩”或者掃描下面的二維碼,即可訂閱我的文章。
如果文章對你有幫助,請随手點個贊吧!
(完)