http://stackoverflow.com/questions/638975/how-do-i-tell-if-a-regular-file-does-not-exist-in-bash
Bash File Testing
-b filename
- Block special file
-c filename
- Special character file
-d directoryname
- Check for directory Existence
-e filename
- Check for file existence, regardless of type (node, directory, socket, etc.)
-f filename
- Check for regular file existence not a directory
-G filename
- Check if file exists and is owned by effective group ID
-G filename set-group-id
- True if file exists and is set-group-id
-k filename
- Sticky bit
-L filename
- Symbolic link
-O filename
- True if file exists and is owned by the effective user id
-r filename
- Check if file is a readable
-S filename
- Check if file is socket
-s filename
- Check if file is nonzero size
-u filename
- Check if file set-user-id bit is set
-w filename
- Check if file is writable
-x filename
- Check if file is executable
if [ ! -f /tmp/foo.txt ];
then
echo "File not found!"
fi
Or written in a slightly different way:
if [ ! -f /tmp/foo.txt ]
then echo "File not found!"
fi
Or you could use:
if ! [ -f /tmp/foo.txt ]
then echo "File not found!"
fi
Or, presing all together:
if ! [ -f /tmp/foo.txt ]; then echo "File not found!"; fi
Which may be written (using then "and" operator: &&) as:
[ ! -f /tmp/foo.txt ] && echo "File not found!"
Which looks shorter like this:
[ -f /tmp/foo.txt ] || echo "File not found!"
FILE=$1
if [ -f $FILE ]; then
echo "File '$FILE' Exists"
else
echo "The File '$FILE' Does Not Exist"
fi