Skip to content
TrySitePrice

How to check if file does not exist in Bash

Best/Tutorial

You can check if a file does not exist in Bash by using the ! -f or ! -e operator. For example:

if ! [ -f "/path/to/file" ]; then
n echo "File does not exist"
fi

Or

if [ ! -e "/path/to/file" ]; then
n echo "File does not exist"
fi

Both of these commands will check if the file located at “/path/to/file” does not exist, and if it does not, the script will output “File does not exist”. The -f option checks if the file exists and is a regular file, and the -e option checks if the file exists regardless of type.

n(https://getdelmar.com)