Linux通过if语句怎样能判断文件或目录是否存在的
发布时间:2020-06-16 点击数:1464
判断文件或者目录是否存在这是需要常做的事 ,那么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语句判断文件或目录是否存在的详细内容,想要老家更多服务器有关知识,欢迎关注云网时代,云网时代为广大用户提供专业化深圳服务器租用,深圳服务器托管,深圳主机租用,云服务器租用等服务器资源,详情欢迎咨询客服了解。

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语句判断文件或目录是否存在的详细内容,想要老家更多服务器有关知识,欢迎关注云网时代,云网时代为广大用户提供专业化深圳服务器租用,深圳服务器托管,深圳主机租用,云服务器租用等服务器资源,详情欢迎咨询客服了解。