简介

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

语法格式

type [OPTIONS…] [COMMAND]

常用参数

-a 显示包含可执行文件名的所有位置, 包括别名、内置函数和函数。
如果同时使用 -p 选项,则不显示别名
-t 描述命令的类型
-p 如果给出的指令为外部指令,则显示其绝对路径

命令的类型

alias 别名
keyword 关键字,Shell保留字
function 函数,Shell函数
builtin 内建命令,Shell内建命令
file 文件,磁盘文件,外部命令
  1. [root@gkdaxue ~]# type ls
  2. ls is aliased to `ls --color=auto'
  3. [root@gkdaxue ~]# type cd
  4. cd is a shell builtin
  5. [root@gkdaxue ~]# type for
  6. for is a shell keyword
  7. [root@gkdaxue ~]# type -t rpm
  8. file
  9. [root@gkdaxue ~]# source /etc/init.d/functions
  10. [root@gkdaxue ~]# type -t apply_sysctl
  11. function

示例

  1. ## -a 显示包含可执行文件名的所有位置
  2. [root@gkdaxue ~]# type -a ls
  3. ls is aliased to `ls --color=auto'
  4. ls is /usr/bin/ls
  5. ## -ap 命令,显示可执行文件的所有位置,但是不显示别名
  6. [root@gkdaxue ~]# type -ap ls
  7. /usr/bin/ls
  8. [root@gkdaxue ~]# type -p cat
  9. /usr/bin/cat