In bash command -d is to check if the directory exists or not.
For example, I having a directory called
/home/sureshkumar/test/.
The directory variable contains:
"/home/sureshkumar/test/"
if [ -d $directory ]
This condition will be true only when a directory exists.
I have changed the directory variable to
"/home/a/b/".
This directory does not exist.
if [ -d $directory ]
Now, the condition is false. If I put the ! in front of my directory does not exist, then this if the condition is true. If this directory does exists then the
if [ ! -d $directory ]
condition is false.
The procedure of the ! the operator is if this condition is true, then it gives the condition is false. If the command is false then it says the command is true. This is the work of! operator.
if [ ! -d $directory ]
This command true only if the $directory does not exist. If the directory exists, it returns false.
To know about Linux join the Linux training
Do check out the video below