The shell commonly used file judgment operators are as follows:
-e file is present
-F file is a normal file (not a directory, device file, linked file)
-S means that the file size is not 0
-D Indicates whether the file is a directory
-B indicates a block device (optical drive, floppy disk, etc.)
-C means a character device (keyboard, sound card, etc.)
-P indicates a pipeline
-H indicates a symbolic link
-S indicates whether the socket
-R,-W,-X Indicates whether the file has readable, writable, executable permissions (refers to the user running the test command)
F1-NT F2 F1 is newer than F2 (new than)
F1-ot F2 F1 is older than F2 (old than)
F1-EF F2 F1 and F2 are hard links to the same file
Use! When the above results are reversed, because the content is more, not listed here. The following example can be used as a programming reference
myfile="Aa.txt"if[!-f $myfile]; Then Echo$myfile"is not exist" Touch$myfileElse Echo$myfile"is exist"fiif[!-s $myfile]; Then Echo "Hello, my master">$myfileElse Echo$myfile"is not null"fi
Shell Script Learning (3) file judgment