To check if a file exists in a bash shell script, use the following:
1 2 3 4 5 |
FILE="/some/path/file" if [ -f "$FILE" ]; then # perform some action if $FILE exists. fi |
To check if a file does not exists in a bash shell script, use the following:
1 2 3 |
if [ ! -f "$FILE" ]; then # perform some action if $FILE does not exists. fi |