转自:http://codingstandards.iteye.com/blog/831504

用途说明

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 ~]#

[转]Linux之type命令的更多相关文章

  1. 【转】linux之type命令

    转自: http://codingstandards.iteye.com/blog/831504 用途说明 type命令用来显示指定命令的类型.一个命令的类型可以是如下之一 alias 别名 keyw ...

  2. Linux type命令

    用途说明 type命令用来显示指定命令的类型.一个命令的类型可以是如下几种: alias 别名 keyword 关键字,Shell保留字 function 函数,Shell函数 builtin 内建命 ...

  3. linux type命令用法_转

    转自:http://codingstandards.iteye.com/blog/831504 在脚本中type可用于检查命令或函数是否存在,存在返回0,表示成功:不存在返回正值,表示不成功. $ t ...

  4. linux下的type命令

    type命令用来显示指定命令的类型.一个命令的类型可以是如下几种: alias 别名 keyword 关键字,Shell保留字 function 函数,Shell函数 builtin 内建命令,She ...

  5. linux中查找命令find、locate、whereis、which、type区别

    linux中查找命令find.locate.whereis.which.type区别 1. find Java代码 find是最常见和最强大的查找命令,你可以用它找到任何你想找的文件.与查询数据库(/ ...

  6. linux type 命令和Linux的五个查找命令

    type命令用来显示指定命令的类型.一个命令的类型可以是如下之一 alias 别名 keyword 关键字,Shell保留字 function 函数,Shell函数 builtin 内建命令,Shel ...

  7. linux中查找命令find、locate、whereis、which、type的区别

    find find是最常见和最强大的查找命令,你可以用它找到任何你想找的文件.与查询数据库(/var/lib/locatedb)文件不同,find查找的是磁盘空间. locate locate命令其实 ...

  8. Linux type命令的用法

    一般情况下,type命令被用于判断另外一个命令是否是内置命令,但是它实际上有更多的用法. 1.判断一个名字当前是否是alias.keyword.function.builtin.file或者什么都不是 ...

  9. linux之find命令详解

    linux之find命令详解 查找文件find ./ -type f查找目录find ./ -type d查找名字为test的文件或目录find ./ -name test查找名字符合正则表达式的文件 ...

随机推荐

  1. android学习笔记二:Intent

    1.Intent作用 协助完成各个组建间的通信.如activity间.启动service.Broadcast. 2.Intent构成 1.Componet name:要启动的目的组建. 2.Actio ...

  2. MyBatis学习总结_13_Mybatis查询之resultMap和resultType区别

    MyBatis的每一个查询映射的返回类型都是ResultMap,只是当我们提供的返回类型属性是resultType的时候,MyBatis对自动的给我们把对应的值赋给resultType所指定对象的属性 ...

  3. MyBatis学习总结_01_MyBatis快速入门

    一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以 ...

  4. Error LNK2019: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(wchar_t *)"

    Error 2 error LNK2019: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToStr ...

  5. [转载]TexturePacker 如何使用自带的加密功能及在cocos2dx中的使用

    在cocos2dx中使用纹理图集是非常节省资源的,在这里推荐 TexturePacker,而且 TexturePacker工具的加密接口也非常的好用,下面就来介绍一下... TexturePacker ...

  6. C# 文本文件打印类库(C#)

    我写了一个打印文本文件的类库,功能包括:打印预览.打印.打印时可以选择打印机,可以指定页码范围.调用方法非常简单:TextFilePrinter p = new TextFilePrinter(tbx ...

  7. svn版本库包含多个项目 ; git svn clone; 某一个子项目,有多个分支;

    情况描述: 公司的svn版本库,包含了多个项目,每个项目对应于1个文件夹 假设版本库名字为Main,其下的项目用 A项目,对应文件夹A B项目,对应文件夹B 通过git svn clone获取了svn ...

  8. 寄售Consignment和VMI有什么区别?

    Consignment 寄存一般是指卖方把货物存放在买方所属仓库,消耗后结帐.库存水平控制和货物的物理管理都由买方负责.这是目前很多大卖场通行的做法.典型的VMI一般也是指卖方把货物存放在买方附近的仓 ...

  9. 第一篇 ERP是什么?-从道的层面浅谈我的理解

    世界上称为ERP软件的软件很多,国外的有SAP,ORACLE,国内的有金蝶,用友,浪潮.这些由不同的厂商开发制作的软件总有其软件适用的场合.这个场合就是企业,而且是市场经济中的企业.个人是不会购买ER ...

  10. 台湾P2P平台

    2014年6月28日下午1:30,“2014两岸三地P2P网贷行业高峰论坛”在上海会展中心友谊会堂如期举行,现场高朋满座,来自全国各地的众多知名P2P网站平台的负责人参与了讨论,并就当前P2P行业的一 ...