用途说明

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

Linux命令之type - 显示命令的类型的更多相关文章

  1. linux怎么样显示命令历史后又显示命令的输入时间

    linux的bash内部命令history就可以显示命令行的命令历史,默认环境执行 history命令后,通常只会显示已执行命令的序号和命令本身.如果想要查看命令历史的时间戳,那么可以执行: 临时显示 ...

  2. Linux命令学习总结: file命令

    命令简介: 该命令用来识别文件类型,也可用来辨别一些文件的编码格式.它是通过查看文件的头部信息来获取文件类型,而不是像Windows通过扩展名来确定文件类型的. 执行权限 :All User 指令所在 ...

  3. Linux:file命令显示自定义文件类型

    file 命令可以查看文件类型信息,原理见: 非常Linux-file命令与magic file 修改 /ect/magic 文件后,可用 file 命令显示自定义文件类型信息. man magic ...

  4. Linux命令之type

    1:linux命令可以分为很多类,其中常见得类型: (1):builtin --内置命令 (2):alias --命令别名 (3):file --外部命令 具体有哪些内置命令以及内置命令各个用法: [ ...

  5. Linux下相关查找文件命令(find locate which whereis type)

    以下内容摘自:http://blog.csdn.net/jessica1201/article/details/8139249 标注的内容为自己的补充: 我们经常需要在系统中查找一个文件,那么在lin ...

  6. linux下的type命令

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

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

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

  8. 我使用过的Linux命令之file - 检测并显示文件类型

    摘自:http://codingstandards.iteye.com/blog/804463 我使用过的Linux命令之file - 检测并显示文件类型 用途说明 file命令是用来检测并显示文件类 ...

  9. Linux编程 10 (shell外部命令与内建命令,alias ,type命令)

    一.  内部命令 Linux命令有内部命令(内建命令)和外部命令之分,内部命令和外部命令功能基本相同,但也有些细微差别.内部命令不需要使用子进程来执行,它们已经和shell编译成一体,作为shell工 ...

随机推荐

  1. 纯css3实现的幽灵按钮导航

    之前为大家介绍了好几款导航菜单,今天再给大家带来一款css3实现的幽灵按钮式的导航菜单.导航界面非常好看.右侧是一个css3实现的动画消息图标.效果图如下: 在线预览   源码下载 实现代码: htm ...

  2. Maven学习之(二)Maven插件创建项目

    现在这里是已经在eclipse上成功的安装了Maven的插件后的操作,简单的创建一个项目, 同时实现Maven功能. 前提条件: 1.JDK 2.maven安装好 3.eclipse上maven插件安 ...

  3. JS地毯式学习三

    1. 插件是一类特殊的程序 . 他可以扩展浏览器的功能 , 通过下载安装完成 . 比如 , 在线音乐.视频动画等等插件. // 检测非 IE 浏览器插件是否存在function hasPlugin(n ...

  4. MongoDB 简介及安装

    什么是MongoDB ? MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统. 在高负载的情况下,添加更多的节点,可以保证服务器性能. MongoDB 旨在为WEB应用提供 ...

  5. StarRTC , AndroidThings , 树莓派小车,公网环境,视频遥控(一)准备工作

    原文地址:http://blog.starrtc.com/?p=48 啥也不说,先来个视频看看效果 视频播放器     00:00   00:54     概述为了体现StarRTC的实时音视频传输能 ...

  6. 上手并过渡到PHP7(2)——必须传递int, string, bool参数?没问题

    Type hints, Type safe 泊学实操视频 泊学原文链接PHP 7中最引人注目的新特性之一,无疑是Scalar type hints.我们可以在函数参数和返回值中使用scalar typ ...

  7. Qt/C++ 构造函数与explicit

    1.默认构造函数 默认构造函数是指所有参数都提供了默认值的构造函数,通常指无参的构造函数或提供默认值的构造函数.如类Test1和Test2的构造函数 class Test1 { public: Tes ...

  8. fanqiang_bak

  9. Java多例模式

    多例模式又划分为有上限多例模式和无上限多例模式两种,没上限的多例模式和直接 new 一个对象没什么差别,此处不做记录. 有上限多例模式:实际上是单例模式的推广,如果它的上限是1,那么就成了单例模式了. ...

  10. 建议 for 语句的循环控制变量的取值采用“半开半闭区间”写法

    建议 for 语句的循环控制变量的取值采用“半开半闭区间”写法. #include <iostream> /* run this program using the console pau ...