shell 判断文件是否存在
发布网友
发布时间:2022-05-18 09:19
我来回答
共2个回答
热心网友
时间:2023-10-13 08:57
一小段帮助
man [
-d file True if file exists and is a directory.
-f file True if file exists and is a regular file.
-h file True if file exists and is a symbolic link.
所以判断是否存在:
[ -d file ] && echo "exist" || echo "not exist"
热心网友
时间:2023-10-13 08:58
if [ -e /path/to/file ];then
echo "OK"
else
echo "No such file"
fi