shell判斷目錄/文件是否存在

1.判斷目錄是否存在bash

dir="/data/www/godev"
if [ -d ${dir} ];then
    echo "exist"
else
    echo "not exist"
fi

2.判斷文件是否存在code

file="/data/www/godev/1.txt"
if [ -f ${file} ];then
    echo "exist"
else
    echo "not exist"
fi

注意: []開始和結尾必定要空格,不然報錯class

相關文章
相關標籤/搜索