type命令使用说明

1、命令概述

type命令用来显示指定命令的类型,判断给出的指令是内部指令还是外部指令。

2、命令语法

type【选项】 【参数】 

3、命令选项

-a:可以显示所有可能的类型,比如有些命令如pwd是shell内建命令,也可以是外部命令。
-p:如果给出的指令为外部指令,则显示其绝对路径;,相当于which命令。
-f:只返回shell函数的信息。
-t:输出所属alias,keyword,function,built-in,file这5种类型的哪个

命令类型:
  alias:别名。
  keyword:关键字,Shell保留字。
  function:函数,Shell函数。
  builtin:内建命令,Shell内建命令。
  file:文件,磁盘文件,外部命令。
  unfound:没有找到。

4、命令示例

4.1 -a 显示命令所有类型:

1 [root@lzg ~]# type ls
2 ls is aliased to `ls --color=auto'
3 [root@lzg ~]# type -a ls
4 ls is aliased to `ls --color=auto'
5 ls is /usr/bin/ls

4.2 .判断一个名字当前是否是alias、keyword、function、builtin、file或者什么都不是:

 1 [root@lzg ~]# type mv
 2 mv is aliased to `mv -i'
 3 [root@lzg ~]# type if
 4 if is a shell keyword
 5 [root@lzg ~]# type cd
 6 cd is a shell builtin
 7 [root@lzg ~]# type ifconfig
 8 ifconfig is /usr/sbin/ifconfig
 9 [root@lzg ~]# type aaa
10 -bash: type: aaa: not found

4.3 -t 判断一个名字当前是否是alias、keyword、function、builtin、file或者什么都不是的另一种方法(适用于脚本编程):

 1 [root@lzg ~]# type -t mv
 2 alias
 3 [root@lzg ~]# type -t cd
 4 builtin
 5 [root@lzg ~]# type -t if
 6 keyword
 7 [root@lzg ~]# type -t ifconfig
 8 file
 9 [root@lzg ~]# type -t aaa              #什么都不是的话,没有提示
10 [root@lzg ~]# 

4.4 查看一个命令的执行路径(如果它是外部命令的话):

1 [root@lzg ~]# type -p ifconfig
2 /usr/sbin/ifconfig
3 [root@lzg ~]# type -p nmtui
4 /usr/bin/nmtui
5 [root@lzg ~]# type -p cut
6 /usr/bin/cut

 

posted @ 2019-11-06 16:06  网络小白-lzg  阅读(1490)  评论(0编辑  收藏  举报