在shell中,可以使用-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"。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: shell怎么取某个字符串后面的内容