Conditional:
$ Result is true when the conditional judgment? Value of 0,
If the result is false is $? Value other than 0
test command is the judge!:
]: ~ $ Test a.txt -nt b.txt determine whether a.txt than b.txt new file, such as a command line format.
But common in programming format is:
]: ~ $ [A.txt -nt b.txt] Analyzing conditions are consistent with the above, it may be substantially without test command
File type is determined
whether or not the file exists determines -e
-d determines whether the directory file
-f determines whether a regular file
-L determines whether the link file
the file is determined whether there is data -s
Analyzing numerical size
-eq determines whether the previous value equal to the value of the back
-nq foregoing judgment values after the value is not equal
-gt previous value is greater than judgment after the value
-lt determination value and previous value is smaller later
- ge determines whether the value is equal to the latter is greater than the previous value
preceding the value -le determines whether or less after the value
File permissions determine
whether -r whether a file read-only access, as long as there is any ugo True
-w determine whether the file has write permissions, as long as there is any ugo True
-x determine whether the file has executable permission, as long as ugo have any true
-u determine whether the file has suid
whether there sgid file -g judge
whether -k whether a file has sbit
文件的时间比较
-nt判断前面的文件是否比后面的文件新 new then
-ot判断前面的文件是否比后面的文件老 old then
-ef判断前后两个文件是否为硬连接文件
字符串判断
-z判断字符串是否为空
-n判断字符串是否有值
==判断前面的字符串是否和后面的字符串一致
!=判断前后两个字符串是否不一致
判断条件叠加
-a两个条件判断叠加,必须两个条件都判断为真,结果才为真
-o两个条件判断叠加,任何一个条件判断为真,结果就为真