shell怎么判断目录是否存在

1252
2024/3/21 11:27:14
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在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怎么取某个字符串后面的内容