File Type:
-F: determines whether the file is a common file.
-D: determines whether the directory is used.
-B: determines whether a device file is a block.
-C: determines whether a device file is a dual-character device file.
-S: Determine whether the socket file is used
-P: Determine whether the MPs queue file is used.
-H: indicates that all values are symbolic links.
-L: The file exists and has symbolic links.
File Size existence:
-E: determines whether a file or directory exists.
-S: the file or directory exists and the size is greater than 0.
File read/write features
-R: determines whether the object has the permission to read.
-W: determines whether a file has the writable permission.
-X: determines whether a file has executable permissions.
-G: determines whether the file has a sgid bit.
-U: determines whether the file has a suid.
-K: determines whether a sticky bit is set. After the sticky bit is set, the file will be written to the cache.
File modification time:
File1-nt file2: Determine if file1 is newer than file2
File1-ot file2: Determine if file1 is older than file2
Instance 1:
Print the directory recursively
#!/bin/bash function readir(){for file in `ls $1`do if [ -d $1"/"$file ] then readir $1"/"$file; else echo $1"/"$file; fidone }readir /tmp
Example 2:
Check whether the files or directories in a directory are readable and writable and executable.
#!/bin/bash function filetest(){for file in `ls $1`do if [ -r $file -a -w $file -a -x $file ] then echo $file; fidone} filetest /tmp