linux如何判断文件夹是否存在

在Linux系统中,可以使用一些命令来判断文件夹是否存在,其中比较常用的是使用test命令或者-d参数。

使用test命令:

if test -d /path/to/directory; then
    echo "Directory exists"
else
    echo "Directory does not exist"
fi

使用-d参数:

if [ -d /path/to/directory ]; then
    echo "Directory exists"
else
    echo "Directory does not exist"
fi

以上两种方式都可以用来判断文件夹是否存在,只需要将/path/to/directory替换为你要判断的文件夹路径即可。如果文件夹存在,则会输出"Directory exists",否则会输出"Directory does not exist"。

阅读剩余
THE END