温馨提示×

shell中怎么判断文件是否存在

小亿
82
2024-06-11 13:29:25
栏目: 编程语言

在shell中可以使用-e参数来判断文件是否存在。具体命令如下:

if [ -e file.txt ]; then
    echo "File exists"
else
    echo "File not found"
fi

其中file.txt为要判断的文件名。如果文件存在,则会输出"File exists";如果文件不存在,则会输出"File not found"。

0