shell 文件测试 蛮全的
-c filename : 当filename 存在并且是字符文件时返回真
-d pathname : 当pathname 存在并且是一个目录时返回真
-e pathname : 当由pathname 指定的文件或目录存在时返回真
-f filename : 当filename 存在并且是正规文件时返回真
-g pathname : 当由pathname 指定的文件或目录存在并且设置了SGID 位时返回真
-h filename : 当filename 存在并且是符号链接文件时返回真 (或 -L filename)
-k pathname : 当由pathname 指定的文件或目录存在并且设置了"粘滞"位时返回真
-p filename : 当filename 存在并且是命名管道时返回真
-r pathname : 当由pathname 指定的文件或目录存在并且可读时返回真
-s filename : 当filename 存在并且文件大小大于0 时返回真
-S filename : 当filename 存在并且是socket 时返回真
-t fd : 当fd 是与终端设备相关联的文件描述符时返回真
-u pathname : 当由pathname 指定的文件或目录存在并且设置了SUID 位时返回真
-w pathname : 当由pathname 指定的文件或目录存在并且可写时返回真
-x pathname : 当由pathname 指定的文件或目录存在并且可执行时返回真
-O pathname : 当由pathname 存在并且被当前进程的有效用户id 的用户拥有时返回真(字母O 大写)
-G pathname : 当由pathname 存在并且属于当前进程的有效用户id 的用户的用户组时返回真
file1 -nt file2 : file1 比file2 新时返回真
file1 -ot file2 : file1 比file2 旧时返回真
test -c /dev/hda ; echo $? // 将打印 1 表示test 命令的返回值为1,/dev/hda 不是字符设备
[ -w /etc/passwd ]; echo $? // 查看对当前用户而言,passwd 文件是否可写
-o 逻辑或,操作符两边一边为真,结果为真,否则为假。
! 逻辑否,条件为假,结果为真。
举例: [ -w result.txt -a -w score.txt ] ;echo $? // 测试两个文件是否均可写
-n string : 字符串string 为非空串时返回真
str1 = str2 : 字符串str1 和字符串str2 相等时返回真
str1 != str2 : 字符串str1 和字符串str2 不相等时返回真
str1 < str2 : 按字典顺序排序,字符串str1 在字符串str2 之前
str1 > str2 : 按字典顺序排序,字符串str1 在字符串str2 之后
int1 -ne int2 : 如果int1 不等于int2,则返回真
int1 -lt int2 : 如果int1 小于int2,则返回真
int1 -le int2 : 如果int1 小于等于int2,则返回真
int1 -gt int2 : 如果int1 大于int2,则返回真
int1 -ge int2 : 如果int1 大于等于int2,则返回真
x=a ; [ $x -eq "1" ] // shell 打印错误信息 [: a: integer expression expected
转贴自:http://blog.chinaunix.net/u/21352/showart_135230.html
shell 文件测试 蛮全的的更多相关文章
- shell文件测试,菜单表示思想
---恢复内容开始--- 文件测试表达式 -f 文件存在且为普通文件 -d 文件存在且为目录文件 -s 文件大小不为0则真 -e 文件存在则真 -r 文件存且可 ...
- Shell 文件测试运算符
文件测试运算符 文件测试运算符用于检测 Unix 文件的各种属性. 属性检测描述如下: 操作符 说明 举例 -b file 检测文件是否是块设备文件,如果是,则返回 true. [ -b $file ...
- shell运算符之 关系运算符,算数运算符,布尔运算符,字符串运算符和文件测试运算符
shell运算符有很多,关系运算符,算数运算符,布尔运算符,字符串运算符和文件测试运算符 1,算术运算符 原声bash 不支持简单的算术运算,可以使用expr 工具 两点注意: 表达式和运算符之间要有 ...
- shell之算数运算符、逻辑运算符、关系运算符、布尔运算符、文件测试运算符
注意事项: (1)bash不支持简单的数学运算,但是可以通过其他命令来实现,例如 awk 和 expr,expr 最常用: (2)完整的表达式要被 ` ` 包含,注意这个字符不是常用的单引号,在 Es ...
- shell脚本中文件测试
shell脚本中文件测试 author:headsen chen 2017-10-17 14:35:19 个人原创,转载请注明作者,否则 依法追究法律责任 [ -f filename ] ...
- (转)shell脚本之文件测试操作符及整数比较符
shell脚本之文件测试操作符及整数比较符 原文:http://www.cnblogs.com/Steward-Xu/p/6722592.html 一.文件测试操作符: 在书写测试表达式是,可以使用一 ...
- shell脚本之文件测试表达式
1.文件测试表达式的用法 我们在编程时处理一个对象时,需要对对象进行测试,只有符合要求的才采取操作处理:这样做的好处是避免程序出错以及无所畏的消耗系统资源,这个测试的对象可以是文件.字符串.数字等. ...
- Linux Shell 04 数字/字符串/文件测试
一. 数字测试 格式:n1 -op n2 测试操作op: eq/ne/le/ge/lt/gt --> 等于/不等于/小于等于/大于等于/小于/大于 1. 数字比较可以使用特殊的( ...
- [shell基础]——整数比较;字符串比较;文件测试;逻辑测试符
整数比较方法一:[ ] 或 [[ ]] (1) 此方法需要使用整数比较运算符.[标注:equal 等于 greater 大于 less-then 小于] (2) 使用时一定要注意前后一 ...
随机推荐
- AI-Info-Micron-Menu:About Micron
ylbtech-AI-Info-Micron-Menu:About Micron 将数据带入生活 美光科技的存储技术帮助将海量数据化为宝贵见解,重新定义世界使用信息的方式. 1.返回顶部 1. 公司简 ...
- nmp部署(Nginx Mariadb Php-fpm)
#主机:192.168.2.129(mini2) 既是php主机,也是数据库主机#yum install -y php php-fpm php-mysql mariadb-server[root@~ ...
- oracle--事物---
一.什么是事务 事务用于保证数据的一致性,它由一组相关的dml语句组成,该组的dml(数据操作语言,增删改,没有查询)语句要么全部成功,要么全部失败. 如:网上转账就是典型的要用事务来处理,用于保证数 ...
- Windows部署jenkins服务器
本次使用的操作系统: windows server 2012 r2vs版本: vs 2015jenkins: 2.19.4 一.下载jenkins http://mirror.xmission.com ...
- #410div2C. Mike and gcd problem
C. Mike and gcd problem time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 正则表达式需要匹配的内容本身就自带了html转义字符,需要转义,否则无法匹配
1.正则表达式需要匹配的内容本身就自带了html转义字符,需要转义,否则无法匹配 例如,对于"requestNo\":\"3b89957436eaacd8311535e0 ...
- Entity Framework Code-First(4):Simple Code First Example
Simple Code First Example: Let's assume that we want to create a simple application for XYZ School. ...
- Eclipse提交svn错误svn E210003 connection refused by the server
错误明细: org.apache.subversion.javahl.ClientException: svn: E210003: connection refused by the server o ...
- hdu1062
#include<stdio.h> #include<string.h> int main() { int i,n,len,j,k,t; char s1]; scanf(&qu ...
- SqlDataReader
using (mycon) { //using语句与try catch finally结合使用 mycon.Open(); // MessageBox.Show("dakai"); ...