溫馨提示×

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

小億
450
2024-06-11 13:29:25
欄目: 編程語言

在shell中可以使用-e參數(shù)來判斷文件是否存在。具體命令如下:

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

其中file.txt為要判斷的文件名。如果文件存在,則會輸出"File exists";如果文件不存在,則會輸出"File not found"。

0