Linux命令之乐--test
官方文档: help test
File operators:
-a FILE True if file exists.
-b FILE True if file is block special.
-c FILE True if file is character special.
-d FILE True if file is a directory.
-e FILE True if file exists.
-f FILE True if file exists and is a regular file.
-g FILE True if file is set-group-id.
-h FILE True if file is a symbolic link.
-L FILE True if file is a symbolic link.
-k FILE True if file has its `sticky' bit set.
-p FILE True if file is a named pipe.
-r FILE True if file is readable by you.
-s FILE True if file exists and is not empty.
-S FILE True if file is a socket.
-t FD True if FD is opened on a terminal.
-u FILE True if the file is set-user-id.
-w FILE True if the file is writable by you.
-x FILE True if the file is executable by you.
-O FILE True if the file is effectively owned by you.
-G FILE True if the file is effectively owned by your group.
-N FILE True if the file has been modified since it was last read.
FILE1 -nt FILE2 True if file1 is newer than file2 (according to
modification date).
FILE1 -ot FILE2 True if file1 is older than file2.
FILE1 -ef FILE2 True if file1 is a hard link to file2.
String operators:
-z STRING True if string is empty.
-n STRING
STRING True if string is not empty.
STRING1 = STRING2
True if the strings are equal.
STRING1 != STRING2
True if the strings are not equal.
STRING1 < STRING2
True if STRING1 sorts before STRING2 lexicographically.
STRING1 > STRING2
True if STRING1 sorts after STRING2 lexicographically.
Other operators:
-o OPTION True if the shell option OPTION is enabled.
! EXPR True if expr is false.
EXPR1 -a EXPR2 True if both expr1 AND expr2 are true.
EXPR1 -o EXPR2 True if either expr1 OR expr2 is true.
arg1 OP arg2 Arithmetic tests. OP is one of -eq, -ne,
-lt, -le, -gt, or -ge.
Arithmetic binary operators return true if ARG1 is equal, not-equal,
less-than, less-than-or-equal, greater-than, or greater-than-or-equal
than ARG2.
例子:
1. 判断文件是否存在
root@Director test]# test -f demo.sh
[root@Director test]# test -f demo.sh && echo true
true
[root@Director test]# test ! -f demo.sh && echo true
[root@Director test]#
2. 判断字符串是否为空
[root@Director test]# var=hello
[root@Director test]# test -n $var && echo true
true
[root@Director test]# test -z $var && echo true
[root@Director test]#
3.比较
[root@Director test]# var=a
[root@Director test]# test $var = a && echo true
true
Linux命令之乐--test的更多相关文章
- Linux命令之乐--grep
正则表达式基本组成部分 Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE MicrosoftInternetExplorer4 /* St ...
- Linux命令之乐--cat
cat命令的用途是连接文件或标准输入并打印.这个命令常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用. 命令参数: -A, --show-all ...
- Linux命令之乐--sed
sed是stream edit的缩写,是处理文本非常重要的工具. 常见用法: 1. 替换文本 1.1 替换文本中的第一处符合的样式 sed 's/pattern/replace_string' fil ...
- Linux命令之乐--find
find是命令行工具箱中最棒的命令之一. 列出当前目录及其子目录中的文件和文件夹. [root@LAMP WebRoot]# find . -print../index.jsp./upload.jsp ...
- Linux命令之乐--script和scriptplay
script和scriptplay可以把终端会话记录到一个文件中,可以用来制作命令行教学视屏. 开始录制会话 [root@new test]# script -t >timing.log -a ...
- Linux命令之乐--md5sum
md5sum命令用于生成和校验文件的md5值.它会逐位对文件的内容进行校验,它常用于检查文件的完整性. 读取文件的MD5值 [root@new ~]# md5sum /usr/local/sbin/* ...
- Linux命令之乐--read
read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量 -p:后接屏幕输出的提示语句 -n:设定输入的字符个数,当达到指定的个数则自动退出,并将输入赋予给变量 -t:当输 ...
- Linux命令之乐--time
time用于统计命令执行花费的总时间 例一: [root@Director usr]# time ls bin etc games include java lib lib64 libexec loc ...
- Linux命令之乐--awk
1.脚本参数传值 #/bin/bash awk '"} {if(($1==a)) print $2;}' /etc/hosts 执行结果:
- Linux命令之乐--iconv
用法: 实际应用: 批量转换文件编码: [root@wls12c PCK]$ for tfile in `ls -l|awk '{print $9}'`;do echo "iconv -f ...
随机推荐
- Linux两块4TB的数据磁盘创建8TB的Raid0
分区表MBR与GPT的说明: MBR:主引导记录,是传统的分区机制,应用于绝大多数使用BIOS的PC设备,MBR+BIOS,MBR支持32位和64位系统,支持的分区数量有限,MBR只支持不超过2T的硬 ...
- store.js 跨浏览器的localStorage
store.js 跨浏览器的localStorage 我们总是想要储存一些数据在浏览器端,却对复杂的兼容性头疼,store.js很好的解决了这些问题. store.js ☍ 使用它相当简单: // 储 ...
- 关闭危害的端口DOS命令(转载)
rem ipseccmd -w REG -p "HFUT_SECU" -r "Block UDP/137" -f *+0:137:UDP -n BLOCK -x ...
- Ubuntu下安装java
1.首先到java.com下载最新版本的jdk.下面是jdk8的网址: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-dow ...
- [sh]shell脚本栗子
我会定期的把看到的一些好的shell和py脚本搜集在这里,供参考学习: 命令行回收站 推荐一个不相关的:trash-cli,就是命令行版的回收站,它的神奇之处在于不是简单的把文件移动到回收站,而且可以 ...
- C++虚函数解析(转载)
虚函数详解第一篇:对象内存模型浅析 C++中的虚函数的内部实现机制到底是怎样的呢? 鉴于涉及到的内容有点多,我将分三篇文章来介绍. 第一篇:对象内存模型浅析,这里我将对对象的内存模型进 ...
- 安装语言包(LANGUAGE PACKAGE)
by 枫竹丹青 一.说明 在SAP ECC 安装好后,如果是生产版本,通常只有两种语言--英语和德语.这时如需中文环境,则需定义支持的语言类型并导入语言包.如果安装的是IDES版,则系统中已包含了几十 ...
- [Linux内核]软中断、tasklet、工作队列
转自:http://www.cnblogs.com/li-hao/archive/2012/01/12/2321084.html 软中断.tasklet和工作队列并不是Linux内核中一直存在的机制, ...
- jQuery开发中容易忽视的错误
1.引用jQuery库文件的<script>标签,必须放在引用自定义脚本文件的<script>标签之前,否则,就会发生找不到对象:最好在<head>元素中,把引入样 ...
- Pycharm 建立工程,包含多个工程目录