Bash Script to check for a file
Occasionally I need to find out if a file DOES exist and/or a file DOESN’T exist.
Here are a couple of snippets to do just that:
if [ ! -f filename] ; #File that you are looking for isn’t there
do stuff
fi
And the opposite:
if [ -e filename]; #File is there
do stuff
fi
Using code like this can help determine if there an error file was generated during a process or if you are expecting a file to be there that isn’t.
