用途说明

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 只返回指定类型的信息。

举个栗子

常用参数举例:

01 #1. 显示所有可能的类型
02 bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a time
03 time is a shell keyword
04 time is /usr/bin/time
05 #2. 返回外部命令的信息,相当于which
06 bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -p time
07 #3. 只返回shell函数信息
08 bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -f time
09 time is a shell keyword
10 #4. 只返回指定的类型
11 bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -t time
12 keyword

备注:

上面time命令的类型有两个,一个是shell保留字,一个是外部命令,那我们查看帮助的方式可以是

01 bixiaopeng@bixiaopengtekiMacBook-Pro androidshell$ man time
02   
03 NAME
04      time -- time command execution
05  
06 SYNOPSIS
07      time [-lp] utility
08  
09 DESCRIPTION
10      The time utility executes and times utility.  After the utility finishes,
11      time writes the total time elapsed, the time consumed by system overhead,
12      and the time used to execute utility to the standard error stream.  Times
13      are reported in seconds.
14  
15      Available options:
16  
17  
18 ile: *manpages*,  Node: time,  Up: (dir)
19  
20  
21 bixiaopeng@bixiaopengtekiMacBook-Pro androidshell$ info time
22  
23 TIME(1)                   BSD General Commands Manual                  TIME(1)
24  
25 NAME
26      time -- time command execution
27  
28 SYNOPSIS
29      time [-lp] utility
30  
31 DESCRIPTION
32      The time utility executes and times utility.  After the utility finishes,
33      time writes the total time elapsed, the time consumed by system overhead,
34      and the time used to execute utility to the standard error stream.  Times
35 -----Info:(*manpages*)time,53 行 --Top-------------------------------------
36 欢迎使用 Info 4.8 版。输入 ? 以获得帮助,m 将得到菜单。

常用命令举例:

01 bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a ls
02 ls is /bin/ls
03 bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a who
04 who is /usr/bin/who
05 bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a cd
06 cd is a shell builtin
07 cd is /usr/bin/cd
08 bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a which
09 which is /usr/bin/which
10 bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a mvn
11 mvn is /usr/share/java/maven-3.0.3/bin/mvn
12 mvn is /usr/bin/mvn
13 bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a adb
14 adb is /Users/bixiaopeng/DevelopSoft/adt-bundle-mac/sdk/platform-tools/adb
15 bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type -a aapt
16 aapt is /usr/local/bin/aapt
17  
18 bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type grep
19 grep is aliased to `grep --color=always'
20 bixiaopeng@bixiaopengtekiMacBook-Pro ~$ type awk
21 awk is /usr/bin/awk 

Linux type命令的更多相关文章

  1. linux type命令用法_转

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

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

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

  3. Linux type命令的用法

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

  4. [转]Linux之type命令

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

  5. linux下的type命令

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

  6. 【转】linux之type命令

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

  7. Linux查找命令对比(find、locate、whereis、which、type、grep)

    //太长不看版find查找磁盘空间,相较于locate和whereis速度较慢.find和locate的查找单位为文件或者目录,locate其实是find -name的另一种写法.locate和whe ...

  8. Linux常用命令type、date

    Linux命令类型: 内置命令(shell内置):cd is shell builtin 外部命令:命令 is /usr/bin/命令,在文件系统的某个路径下有一个与命令名称相应的可执行文件 type ...

  9. Linux下命令行安装weblogic10.3.6

    Linux下命令行安装weblogic10.3.6 一.安装前准备工作: 1.创建用户useradd weblogic;创建用户成功linux系统会自动创建一个和用户名相同的分组,并将该用户分到改组中 ...

随机推荐

  1. 如何反编译DLL文件

    1.利用反编译器,多种工具,本次选用Reflector 8.5. 2.界面如下:

  2. 异常问题解决Error:Execution failed for task ':app:processDebugManifest'

    Error:Execution failed for task ':app:processDebugManifest' www.MyException.Cn  网友分享于:2015-12-28  浏览 ...

  3. [问题2015S10] 复旦高等代数 II(14级)每周一题(第十一教学周)

    [问题2015S10]  设 \(A\) 为 \(n\) 阶实方阵, 证明: 存在 \(n\) 阶非异实对称阵 \(R\), 使得 \(A'=R^{-1}AR\), 即 \(A\) 可通过非异实对称阵 ...

  4. HDU1532 Drainage Ditches 网络流EK算法

    Drainage Ditches Problem Description Every time it rains on Farmer John's fields, a pond forms over ...

  5. 特征创建:Reference Characteristic、Template

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  6. IE浏览器bug罪魁祸首--hasLayout

    IE浏览器一直都是前端程序员最头疼的,IE的表现与其他浏览器不同的原因之一就是,显示引擎使用一个称为布局(layout)的内部概念. 认识hasLayout--haslayout是Windows In ...

  7. C语言细节——献给入门者(三)

    C语言细节——献给入门者(三) >>主题:关于强制类型转换 先来瞎扯下强制类型转换,c语言有很多数据类型,long,short,int,float,double,bool,char等等.当 ...

  8. io流操作大全

    JAVA 中的IO流 一.流的概念        流(stream)的概念源于UNIX中管道(pipe)的概念.在UNIX中,管道是一条不间断的字节流,用来实现程序或进程间的通信,或读写外围设备.外部 ...

  9. linux下查看某软件是否已安装, ubuntu安装deb包

    1.rpm包安装的,可以用rpm -qa看到,如果要查找某软件包是否安装,用 rpm -qa | grep “软件或者包的名字”. [root@hexuweb102 ~] rpm -qa | grep ...

  10. iOS 启动图那些坑

    当我们按照图片尺寸要求将所有的图片添加到工程中后,上传打包的工程时可能会出现一个问题:说工程中不存在启动图.但是我们明明已经导入启动图了,那么问题出在哪呢.我经过多次试验,发现压缩过后的图片作为启动图 ...