Bash check if a directory exists

Written by Yujin Boby

Edit in WordPress

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