c语言判断文件夹是否存在 linux判断目录是否存在-d?

linux判断目录是否存在-d?例如,如果[-D/test/test1],那么echo “directory exists”else MKDIR-P/test/test1 fi两种方法:查找命令或sh

linux判断目录是否存在-d?

例如,如果[-D/test/test1],那么echo “directory exists”else MKDIR-P/test/test1 fi

两种方法:查找命令或shell脚本。

1. Find命令

Find是Linux中查找文件的常用方法。

Find语法:Find[specify search directory][search rule][action executed after search

]例如:Find/tmp-name wa*-type L是在/tmp下查找具有wa名称和符号链接类型的文件。如果你找到它,就意味着它存在。

2. [shell脚本

在文件的自动处理中,经常需要自动判断。以下脚本判断测试日志如果存在,则文件存在。否则,文件不存在。

示例:编辑脚本以确定文件是否存在

VI T.Sh;!/bin/bash

如果[-E/temp/测试日志];然后//这里是判断语句,其中-e表示如果比较结果为真,则它存在

echo“file exists”

else

echo“file does not exist”

fi

save exit

execute:

sh T.sh