Linux系統中Type命令如何使用

2021-10-25 14:57:40 字數 1598 閱讀 4593

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

[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工具用於顯示命令的型別資訊。它將展示在命令列上輸入給定的命令將如何解釋。

type命令及Linux命令型別

type後跟乙個指令,會展示當該指令作為乙個命令時是如何解讀的。引數 a,type會列印指令的所有位置。引數 t,type會列印alias,keyword,function,builtin,file的之一。alias 別名。keyword shell保留字。function shell函式。buil...

shell中的type命令

type aftpp name name,a 列印name的所有可能情況,比如type a ls,會列印ls is aliased to ls color auto 和ls is bin ls f 不會去查詢function t 列印alias,keyword,function,built in,f...

Linux命令型別和執行順序 type命令

type命令 用來顯示指定命令的型別,判斷給出的指令是內部指令還是外部指令。type檢視的linux中的命令型別 alias 別名。keyword 關鍵字,shell保留字。function 函式,shell函式。builtin 內建命令,shell內建命令。file 檔案,磁碟檔案,外部命令。un...