如何用shell判断一个文件是否存在

avatar
作者
筋斗云
阅读量:0

可以使用以下shell脚本来判断一个文件是否存在:

#!/bin/bash  file="/path/to/file"  if [ -f "$file" ]; then     echo "File exists" else     echo "File does not exist" fi 

上面的脚本首先定义了要判断的文件路径,然后使用-f选项来判断文件是否存在。如果文件存在,则输出"File exists",否则输出"File does not exist"。

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!