linux type命令用法_转
转自:http://codingstandards.iteye.com/blog/831504
在脚本中type可用于检查命令或函数是否存在,存在返回0,表示成功;不存在返回正值,表示不成功。
$ type foo >/dev/null 2>&1 || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }
用途说明
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
linux type命令用法_转的更多相关文章
- linux mail命令用法
在Linux系统下mail命令的测试 1. 最简单的一个例子: mail -s test admin@aispider.com 这条命令的结果是发一封标题为test的空信给后面的邮箱,如果你有mta并 ...
- (转)linux paste命令用法详解
linux paste命令用法详解原文:http://www.xfcodes.com/linuxcmd/mulu/10211.htmlinux下paste命令,可用于合并文件的列. 功能说明:合并文件 ...
- Linux type命令的用法
一般情况下,type命令被用于判断另外一个命令是否是内置命令,但是它实际上有更多的用法. 1.判断一个名字当前是否是alias.keyword.function.builtin.file或者什么都不是 ...
- Linux——基础命令用法(下)
一.linux用户 1.什么是用户 用户是用来运行某一些进程.拥有某一些文件或目录. 在Linux里面,用户分成三大类:root用户.系统用户.普通用户. 用户是用UID来唯一标识身份的,且root用 ...
- Linux type命令
用途说明 type命令用来显示指定命令的类型.一个命令的类型可以是如下几种: alias 别名 keyword 关键字,Shell保留字 function 函数,Shell函数 builtin 内建命 ...
- linux type 命令和Linux的五个查找命令
type命令用来显示指定命令的类型.一个命令的类型可以是如下之一 alias 别名 keyword 关键字,Shell保留字 function 函数,Shell函数 builtin 内建命令,Shel ...
- Linux——基础命令用法(上)
一.Linux基础命令 1.Linux命令行的格式 命令行的格式为:用户名+主机名+当前工作目录 输入内容的命令格式为:命令 [-短选项/--长选项] [参数] [root@localhost ~]# ...
- linux基础命令用法
目录管理 ls.cd.pwd.mkdir.rmdir.tree ls(list) 列出,列表 用法: ls -l:长格式 文件类型: -:普通文件 (f) d: 目录文件 b: 块设备文件 (bloc ...
- linux find命令用法
Linux下find命令在目录结构中搜索文件,并执行指定的操作.Linux下find命令提供了相当多的查找条件,功能很强大.由于find具有强大的功能,所以它的选项也很多,其中大部分选项都值得我们花时 ...
随机推荐
- 使用mutt+msmtp在Linux命令行界面下发邮件
mutt命令执行了却发送不了邮件, 搜索了一会才明白原来是mutt需要一个发信的程序, msmtp刚好是一个不错的选择. 1. apt-get install mutt msmtp (安装过程中会弹出 ...
- Robocopy
用法: http://technet.microsoft.com/zh-cn/library/cc733145%28v=ws.10%29.aspx 图形化工具: http://sourceforg ...
- 给php增加gd库(转)
1.安装zlib tar zxvf zlib-1.2.3.tar.gz cd zlib-1.2.3 ./configure --prefix=/usr/local/zlib make make ins ...
- 【转】区别和认识.Net四个判等函数
原文地址:不详 .Net有四个判等函数?不少人看到这个标题,会对此感到怀疑.事实上确是如此,.Net提供了ReferenceEquals.静态Equals,具体类型的Equals以及==操作符这四个判 ...
- Linux权限问题
Linux中各个用户对文件和目录的权限有三种: r: 读 w:写 x:执行 各个权限的意义: 文件 r:可以读取文件的内容 w:编辑文件内容 x:执行该文件 目录 r:列出该目录下的内容,即使用ls命 ...
- c3p0配置 initialPoolSize 和minPoolSize 可以设为0吗?设0有坏处吗?
c3p0配置 initialPoolSize 和minPoolSize 可以设为0吗?设0有坏处吗? c3p0配置 initialPoolSize 和minPoolSize 可以设为0吗?设0有坏处吗 ...
- HDU 1016 DFS
很简单的深搜 只要看出来是深搜... 注意判断最后一点是否与加一为质数 #include<stdio.h> #include<string.h> #include<alg ...
- PHP 错误与异常 笔记与总结(12 )异常
① 异常的概念:异常和错误的区别 PHP 部分借鉴了 C++ 和 JAVA 中的异常处理机制.PHP 中的异常是指 程序运行和预期不太一致,与错误是两个不同的概念. ② 异常的语法结构 [例1] &l ...
- UIButton 长按点击 背景改变效果
1.添加按钮的点击事件和按下事件 [btn setImage:[UIImage imageNamed:@"NorMal.png"] forState:UIControlStateN ...
- Linux命令echo -e
在Linux命令中 echo -e 这个参数e是什么意思. echo –e “I will use ‘touch’ command to create 3 files.” 这里参数e的作用是什么 ma ...