Directory

DevOps Ubuntu Shell Script: Directory

Directory exist

#!/bin/sh
 
if [ -d "/path/to/dir" ]; then
    echo "Directory /path/to/dir exists."
else
    echo "Directory /path/to/dir does not exists."
fi
#!/bin/sh
	
[ -d /path/to/dir ] && echo "Directory exists" || echo "Directory not exists"

Directory not exist and create new folder

#!/bin/sh
[ ! -d /path/to/not-exist-dir ] && mkdir -p /path/to/not-exist-dir

Reference