简介
type命令用来显示指定命令的类型,判断给出的指令是内部指令还是外部指令。
语法格式
type [OPTIONS…] [COMMAND]
常用参数
-a | 显示包含可执行文件名的所有位置, 包括别名、内置函数和函数。 如果同时使用 -p 选项,则不显示别名 |
---|---|
-t | 描述命令的类型 |
-p | 如果给出的指令为外部指令,则显示其绝对路径 |
命令的类型
alias | 别名 |
---|---|
keyword | 关键字,Shell保留字 |
function | 函数,Shell函数 |
builtin | 内建命令,Shell内建命令 |
file | 文件,磁盘文件,外部命令 |
空 |
[root@gkdaxue ~]# type ls
ls is aliased to `ls --color=auto'
[root@gkdaxue ~]# type cd
cd is a shell builtin
[root@gkdaxue ~]# type for
for is a shell keyword
[root@gkdaxue ~]# type -t rpm
file
[root@gkdaxue ~]# source /etc/init.d/functions
[root@gkdaxue ~]# type -t apply_sysctl
function
示例
## -a 显示包含可执行文件名的所有位置
[root@gkdaxue ~]# type -a ls
ls is aliased to `ls --color=auto'
ls is /usr/bin/ls
## -ap 命令,显示可执行文件的所有位置,但是不显示别名
[root@gkdaxue ~]# type -ap ls
/usr/bin/ls
[root@gkdaxue ~]# type -p cat
/usr/bin/cat