If you are working on a Bash script that interacts with directories, you might encounter a situation where you need to make sure that the directory exists.
Question arises how to check if directory exists in bash shell?
The answer is fairly simple. You can use the -d in your conditional statement. Something like this:
if [ -d directory_name ]
echo "Directory exists"
You can also use negation here:
if [ ! -d directory_name ]
echo "Directory doesn't exist"
That’s it. That’s all you need to do for checking if a directory exists in bash shell or not.