使用test测试目录是否存在

test -d "DIRECTORY" && echo "Found/Exists" || echo "Does not exist"

示例

DIR="/etc/httpd/"
if [ -d "$DIR" ]; then
  echo "Installing config files in ${DIR}..."
else
  echo "Error: ${DIR} not found. "
  exit 1
fi

在linux中检查目录是否存在,如果不存在,则创建

#!/bin/bash
dir="/app/itr"

[ ! -d "$dir" ] && mkdir -p "$dir"

如何在linux中检查一个目录是否存在

使用 -d 判断

[ -d "/path/dir/" ] && echo "目录存在"

使用 ! -d 判断

[ ! -d "/dir1/" ] && echo "目录不存在"
在linux shell中如何判断目录是否存在
日期:2019-04-29 03:17:51 来源:oir作者:oir