1.文件的检测
test -option file
-e file是否存在
-f file是否是文件
-d file是否是目录
-s file是否为空白文件
-r 是否可读
-w 是否可写
-x 是否可执行
2.两个文件之间的比较
test file1 -nt file2 file1 is newer than file2
test file1 -ot file2 file1 is older than file2
3.两个整数之间的比较
test n1 -option n2
-eq n1 equal n2
-ne n1 not equal n2
-gt n1 is greater than n2
-lt n1 is less than n2
-ge n1 is greater than or equal n2
-le n1 is less than or equal n2
4.字符串之间的比较
test -z string 判断string是否为0,若为空串,返回true
test -n string 判断string是否不为0,若为空串,返回false
5.多重条件判断
test -r file -a -w file
-a and
-o or
! not
eg1:test -e file && echo "文件file存在!"
eg2: test file1 -nt file2 && echo "file1 is newer than file2 !"