温馨提示×

怎么用shell判断一个文件是否存在

小亿
90
2024-02-26 11:26:27
栏目: 编程语言

可以使用以下命令来判断一个文件是否存在:

if [ -f /path/to/file ]; then
    echo "File exists"
else
    echo "File does not exist"
fi

这里-f选项用来判断文件是否存在且是普通文件。如果文件存在,则输出"File exists",否则输出"File does not exist"。可以根据实际情况修改路径和输出信息。

0