Bash check if a directory exists

To check if a directory exists in bash, use

if [[ -d "/path/to/directory/" ]]
then
    echo "Directory found."
fi

To check for absense of a directory, use !

if [[ ! -d "/path/to/directory/" ]]
then
    echo "Directory not found."
fi

See bash

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *