用途说明

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

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

它是Linux系统的一种自省机制,知道了是那种类型,我们就可以针对性的获取帮助。比如内建命令可以用help命令来获取帮助,外部命令用man或者info来获取帮助。

常用参数

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

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

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

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

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

使用示例

示例一 type自己是什么类型的命令

[root@new55 ~]# type -a type
type is
a shell builtin
[root@new55 ~]# help type

type: type [-afptP] name [name ...]
For each NAME, indicate how it
would be interpreted if used as a
command name.

If the -t
option is used, `type' outputs a single word which is one of
`alias',
`keyword', `function', `builtin', `file' or `', if NAME is an
alias,
shell reserved word, shell function, shell builtin, disk file,
or
unfound, respectively.

If the -p flag is used, `type' either
returns the name of the disk
file that would be executed, or nothing if
`type -t NAME' would not
return `file'.

If the -a flag is
used, `type' displays all of the places that contain
an executable named
`file'. This includes aliases, builtins, and
functions, if and only if
the -p flag is not also used.

The -f flag suppresses shell
function lookup.

The -P flag forces a PATH search for each NAME,
even if it is an alias,
builtin, or function, and returns the name of the
disk file that would
be executed.
typeset: typeset [-afFirtx] [-p]
name[=value] ...
Obsolete. See `declare'.
[root@new55 ~]#

示例二 常见命令的类型

[root@new55 ~]# type -a cd
cd is a
shell builtin
[root@new55 ~]# type -a pwd

pwd is a shell builtin
pwd is /bin/pwd
[root@new55 ~]# type -a time
time is a shell keyword
time
is /usr/bin/time
[root@new55 ~]# type -a
date
date is /bin/date
[root@new55 ~]# type -a which
which is aliased to `alias |
/usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
which is
/usr/bin/which
[root@new55 ~]# type -a
whereis
whereis is /usr/bin/whereis
[root@new55 ~]# type -a whatis
whatis is
/usr/bin/whatis
[root@new55 ~]# type -a
function
function is a shell keyword
[root@new55 ~]# type -a ls
ls is aliased to `ls
--color=tty'
ls is /bin/ls
[root@new55 ~]# type -a ll
ll is aliased to `ls -l
--color=tty'
[root@new55 ~]# type -a echo

echo is a shell builtin
echo is /bin/echo
[root@new55 ~]# type -a bulitin
-bash: type: bulitin: not
found
[root@new55 ~]# type -a builtin

builtin is a shell builtin
[root@new55 ~]# type -a keyword
-bash: type: keyword: not
found
[root@new55 ~]# type -a command

command is a shell builtin
[root@new55 ~]# type -a alias
alias is a shell
builtin
[root@new55 ~]# type -a grep

grep is /bin/grep
[root@new55 ~]#

问题思考

相关资料

【1】Blue_Stone's OpenWorld Linux中的type命令
【2】山海经 Linux中的type命令

【3】鸟哥的私房菜 Bash shell 的內建命令: type
【4】阮一峰的网络日志 Linux的五个查找命令

原文地址:http://codingstandards.iteye.com/blog/831504

最新文章

  1. SOLD原则
  2. 微信下输入法在IOS和安卓下的诡异
  3. September 4th 2016 Week 37th Sunday
  4. Android 锁屏软件MemoryDebris测试报告
  5. T-SQL运算符
  6. 无刷新分页 Ajax,JQuery,Json
  7. unity3d shader之Roberts,Sobel,Canny 三种边缘检测方法
  8. 淘宝API举例子
  9. Java中异常的基本应用(一)
  10. typedef的用法总结
  11. Centos6.5下一个Ceph存储集群结构
  12. android Fragment 用法小结
  13. windows 下安装Python
  14. 求两个整数的最大公约数GCM
  15. Xtion pro live OpenNI2.2 Nite 2.2 安装配置1.0
  16. sklearn数据预处理
  17. lesson6-图像分割-小象c
  18. STL六大组件
  19. LOJ 10155 - 「一本通 5.2 例 3」数字转换
  20. FastDFS client for .net

热门文章

  1. 一款纯css3实现的漂亮的404页面
  2. war 宽度变窄
  3. 关于PDNN、Theano、Numpy以及Scipy的安装
  4. C语言 · 输出日历
  5. Unix 系统下的 Nginx 1.4.x
  6. CMM已经落伍了,敏捷才是王道
  7. 【转】PNG图像文件格式
  8. MFC 窗体样式修改
  9. wamp5多站点配置教程
  10. MySQL,SQLSERVER,ORACLE获取数据库表名及字段名