What is the difference between -f and -s options in If condition?
From man test
:
-f FILE FILE exists and is a regular file-s FILE FILE exists and has a size greater than zero
Example
Let's create a file from scratch and check it out.
$ touch b
Does the file exist?
$ [ -f "b" ] && echo "file exists"file exists # yes!!!!
Does the file have a size greater than zero?
$ [ -s "b" ] && echo "file exists and is greater than zero"$ # no!!!!
So a good if-elif-else
condition to check the existence of a file could be:
if [ -s "$file" ]; then echo "exists and it is not empty"elif [ -f "$file" ]; then echo "at least exists"else echo "does not exist"fi