`

我使用过的Linux命令之type - 显示命令的类型

阅读更多

我使用过的Linux命令之type - 显示命令的类型

本文链接: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 ~]#

问题思考

相关资料

【1】Blue_Stone's OpenWorld    Linux中的type命令    
【2】山海经  Linux中的type命令    
【3】鸟哥的私房菜  Bash shell 的內建命令: type   
【4】阮一峰的网络日志    Linux的五个查找命令    

返回 我使用过的Linux命令系列总目录

 

0
0
分享到:
评论

相关推荐

    cmd操作命令和linux命令大全收集

    ping -t -l 65550 ip 死亡之ping(发送大于64K的文件并一直ping就成了死亡之ping) ipconfig (winipcfg) 用于windows NT及XP(windows 95 98)查看本地ip地址,ipconfig可用参数“/all”显示全部配置信息 tlist -t 以...

    适用于linux的命令解析工具,支持 -model=./yolov5l.onnx 和-help 命令解析,向我们常看到命令工

    使用C/C++实现的,适用于linux仿atlas的atc(模型转换工具)命令解析代码,支持命令顺序错乱解析、支持非法命令检查告警、支持--help命令显示所有可输入的命令参数,可自行扩展自身业务逻辑。如:解析以下命令:--...

    Linux中find命令的用法汇总

    如果你想在linux系统的命令行中变得特别高效,那么 find 是你必须掌握的命令之一。 find 命令的基本语法如下: $ find [path] [option] [expression] 一、基本用法 1. 列出当前目录和子目录下的所有文件 这个命令...

    linux常用命令精解

    linux常用命令精解 磁盘管理与维护: Df:显示磁盘的相关信息 -a或-all:包含全部的文件系统 --black-size=<区块大小>:以指定的区块大小来显示区块数目 ...-t<文件系统类型>或—type=<文件系统类型>:反显示指定文件系统

    Linux下ftp命令详解

    Linux下ftp命令详解 FTP> ! 从 ftp 子系统退出到外壳。 FTP> ? 显示 ftp 命令说明。? 与 help 相同。 格式:? [command] 说明:[command]指定需要帮助的命令名称。如果没有指定 command,ftp 将显示全部命令的列表...

    Linux命令大全(Linuxidc.com修改版)

    Linux的很多命令速查~ 如LS命令: 功能说明:列出目录内容。 语 法:ls [-1aAbBcCdDfFgGhHiklLmnNopqQrRsStuUvxX][-I <范本样式>][-T <跳格字数>][-w <每列字符数>][--block-size=<区块大小>][--color=<使用...

    ubuntu/linux下实现自己的命令

    具体命令:DIR(my_ls), RD(my_rd),CD,MD(my_md), DEL,MOVE(my_move),REN(my_ren),XCOPY, PROMPT,SORT(sort),TYPE(my_type),COPY(my_copy),命令格式可参照 Windows 的 CMD.EXE 或 MS-DOS 提供的命令; 设计命令的...

    入门学习Linux常用必会60个命令实例详解doc/txt

    要想真正理解Linux系统,就必须从Linux命令学起,通过基础的命令学习可以进一步理解Linux系统。 不同Linux发行版的命令数量不一样,但Linux发行版本最少的命令也有200多个。这里笔者把比较重要和使用频率最多的命令...

    第四课:创建目录之MD命令的详解.exe

    第11课:文件管理之type命令的使用 第12课:文件管理之文件属性的设置-attrib命令 第13课:ipconfig 命令详解 第14课:设置启动选项与服务--MSConfig命令 第15课:查看计算端口信息 第16课:测试网络连接命令 第17课...

    linux终端窗口下的打字练习软件

    接着进行编译,输入如下命令:gcc -o easy-type easy-type.c ,然后输入命令: ./easy-type ,就可以运行这个程序了。 使用说明请查看解压缩以后的RAEDME.txt 文件。 这个软件有一个小缺点,但是不影响使用。

    Linux中find命令的用法入门

    Linux系统下的Find 命令具有很强大的搜索功能,可以遍历整个文件系统。所以 find 命令很耗资源,有时候甚至会耗费很长时间,因此建议把它放在后台执行。 Find 命令格式如下所示: find pathname -options [-print -...

    【Linux命令篇】find命令-查找与清理过期文件

    1、目录层级、文件类型、文件名过滤查找 find /data -maxdepth 1 -type f -name *.sh find /data -maxdepth 1 -type d -name code 2、逻辑操作符,与-a、或-o、非! find /data -name *.sh -a -name *test* find /...

    windows实用dos命令大全

    TYPE[盘符:][路径]〈文件名〉|MORE,MORE为分屏显示命令,使用些参数后当满屏时会暂停,按任意键会继续显示。  (5)若需将文件内容打印出来,可用如下格式:  TYPE[盘符:][路径]〈文件名〉,>PRN  此时,...

    Linux 命令入门文档.zip

    - 学习 Bash 的基础知识。具体地,在命令行中输入 `man ...你可以用 `type 命令` 来判断这个命令到底是可执行文件、shell 内置命令还是别名。 - 学会使用 `>` 和 `来重定向输出和输入,学会使用 `|` 来重定向管道。

    Linux系统总复习.txt

    3、Linux常用命令 重点 1)文件处理命令 ls -a -l -d -i ls -l 查看文件详细内容-文件权限ugo rwx ls -d 显示目录,不显示目录下子文件 cd pwd mkdir -p -p 递归 tree touch cp -r -p -d -a -p 保留...

    LInux find使用

    LInux 中find命令的使用方法

    Linux 命令find之查找文件的示例

    如果在使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件,并且将查找到的子目录和文件全部进行显示。 语法:find + 目标目录(路径) + <选项> + 参数 常用选项列表 选项 含义 -...

    consoletype命令 输出已连接的终端类型

    consoletype命令用于打印已连接的终端类型到标准输出,并能够检查已连接的终端是当前终端还是虚拟终端。 语法格式:consoletype 参考实例 输出已连接的终端类型: [root@linuxcool ~]# consoletype 与该功能相关的...

    Linux操作系统实验三.doc

    (3)free命令:显示系统内存的使用情况,包括内存总量、已经使用内存数量,空闲内存数量等信息。 (4) top命令:实时监控系统进程。 (5)sleep 命令:用于使进程延迟一段时间再执行。 其格式为: sleep time; command (6...

    file-5.25-mips32r1-linux-static.tar.gz

    Unix/Linux常用命令,file-5.25移植到MIPS32平台,在bcm6838 SoC、MIPS r34Kc测试通过。编译环境:Ubuntu-16.04-LTS,32位,GCC编译器:crosstools-mips-gcc-4.6-linux-3.4-uclibc-0.9.32-binutils-2.21,mips-...

Global site tag (gtag.js) - Google Analytics