Test mark |
Meaning |
File name and type |
-E |
Whether the file name exists |
-F |
Whether the file name exists and is a file |
-D |
Whether the file name exists and is a directory |
-B |
Whether the file name exists and is a block |
-C |
Whether the file name exists and is a character device |
-S |
Whether the file name exists and is a socket File |
-P |
Whether the file name exists and is a FIFO (pipe) File |
-L |
Whether the file name exists and is a connection file |
File Permission Detection |
-R |
Checks whether the file name exists and has the "readable" permission |
-W |
Check whether the file name exists and has the "writable" permission |
-X |
Checks whether the file name exists and has the "executable" permission |
-U |
Check whether the file name exists and has the "SUID" permission |
-G |
Checks whether the file name exists and has the "SGID" permission |
-K |
Check whether the file name exists and has the "Sticky bit" permission |
-S |
Checks whether the file name exists and is a non-blank file" |
Comparison of Two files |
-Nt |
(Newer than) determine whether file1 is newer than file2 |
-Ot |
(Older than) checks whether the file is older than file2. |
-Ef |
Determine whether file1 and file2 are the same file, which can be used to determine the hard link |
Determination between numbers |
-Eq |
Equal |
-Ne |
Not equal |
-Gt |
Greater |
-Lt |
Less |
-Ge |
Greater than or equal |
-Le |
Less than or equal |
Judge string data |
Test-z string |
Returns true if the string is null. |
Test-n string |
Determines whether the string is 0. If it is null, false is returned. |
Test str1 = str2 |
Returns true if str1 is equal to str2. |
Test str1! = Str2 |
Judge whether str1 is equal to str2. If it is equal, false is returned. |
Multi-condition judgment |
- |
The two conditions are true at the same time. For example: test-r file a test-x file. If both conditions are true, true is returned. |
-O |
If any condition is true, for example: test-r file o test-x file, true is returned if both conditions are true. |
! |
Reverse status, such as test! -X file: returns true if file does not have x. |