Foreword: When
we write shell scripts, we must operate on the file, so we need to judge the file before the operation. Let's see how to test the file.
The main parameters:
-f file exists and is a normal file, it is true
-d file exists and is a directory, it is true
-s file exists and its size is not 0, it is true
-e file (file or directory) exists, it is true
-r file exists and Readable is true
-w file exists and writeable is true
-x file exists and executable is true
There are many more, such as -b -S -L -O, etc. If you are interested, you can check it out by man test
For example:
these test characters are generally in the format of [-f file]