How do I tell if a file does not exist in Bash?

The test command (written as [ here) has a “not” logical operator, ! (exclamation mark):

if [ ! -f /tmp/foo.txt ]; then
    echo "File not found!"
fi

Leave a Comment