Linux通過if語句怎樣能判斷文件或目錄是否存在的
發(fā)布時間:2020-06-16 點擊數(shù):1577
判斷文件或者目錄是否存在這是需要常做的事 ,那么x通過if語句怎樣能判斷文件或目錄是否存在的
目錄判斷:
path="/home"
#if [ ! -d ${path} ];then
if [ -d ${path} ];then
echo dir ${path} exist!
else
echo dir ${path} not exist!
fi
文件判斷:
file="/home/log.txt"
if [ -f ${file} ];then
echo file ${file} exist!
else
echo file ${file} not exist!
fi
以上就是linux中如何通過if語句判斷文件或目錄是否存在的詳細內(nèi)容,想要老家更多服務器有關知識,歡迎關注云網(wǎng)時代,云網(wǎng)時代為廣大用戶提供專業(yè)化深圳服務器租用,深圳服務器托管,深圳主機租用,云服務器租用等服務器資源,詳情歡迎咨詢客服了解。

path="/home"
#if [ ! -d ${path} ];then
if [ -d ${path} ];then
echo dir ${path} exist!
else
echo dir ${path} not exist!
fi
文件判斷:
file="/home/log.txt"
if [ -f ${file} ];then
echo file ${file} exist!
else
echo file ${file} not exist!
fi
以上就是linux中如何通過if語句判斷文件或目錄是否存在的詳細內(nèi)容,想要老家更多服務器有關知識,歡迎關注云網(wǎng)時代,云網(wǎng)時代為廣大用戶提供專業(yè)化深圳服務器租用,深圳服務器托管,深圳主機租用,云服務器租用等服務器資源,詳情歡迎咨詢客服了解。