How to check directory existence?

QuestionsQuestions8 SkillsProBasic Files OperationsAug, 26 2025
0200

You can check if a directory exists in a Bash script using the -d file test operator. Here’s an example of how to do this:

#!/bin/bash

DIRECTORY="/path/to/directory"

if [ -d "$DIRECTORY" ]; then
    echo "Directory exists."
else
    echo "Directory does not exist."
fi

Replace /path/to/directory with the actual path of the directory you want to check. This script will output whether the specified directory exists or not.

0 Comments

no data
Be the first to share your comment!