[Bash] Check whether a directory exists with -d

Created on November 30, 2026

You can use [ -d path ] in a Bash if statement to check whether a path points to a directory. This example checks for reports in the current working directory.

if [ -d reports ]; then
  echo "The reports directory exists"
fi

If reports is a directory or a symbolic link to a directory, the command prints:

The reports directory exists
Bash