type命令

1,用途说明

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

    alias 别名

    keyword 关键字,Shell保留字

    function 函数,Shell函数

    builtin 内建命令,Shell内建命令

    file 文件,磁盘文件,外部命令

    unfound 没有找到

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

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

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

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

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

3,练习

查看ls的命令类型

[root@localhost ~]# type ls
ls is aliased to `ls --color=tty'
[root@localhost ~]# type -a ls
ls is aliased to `ls --color=tty'
ls is /bin/ls

[root@localhost ~]# type -p ls
[root@localhost ~]# type -f ls
ls is aliased to `ls --color=tty'
[root@localhost ~]# type -t ls
alias

[root@localhost ~]# type cd 
cd is a shell builtin
[root@localhost ~]# type -a cd 
cd is a shell builtin
[root@localhost ~]# type -p cd 
[root@localhost ~]# type -f cd 
cd is a shell builtin
[root@localhost ~]# type -t cd 
builtin
[root@localhost ~]# type whereis 
whereis is /usr/bin/whereis
[root@localhost ~]# type -a whereis 
whereis is /usr/bin/whereis
[root@localhost ~]# type -p whereis 
/usr/bin/whereis
[root@localhost ~]# type -f whereis 
whereis is /usr/bin/whereis
[root@localhost ~]# type -t whereis 
file



你可能感兴趣的:(type,命令类型)