1、linux shell中判断文件是否存在,可以使用test命令的-a参数。借助于if结构进行判断即可。
2、以~/t/thello.py为例,检测这个文件,如果存在将其删除,示例代码如下:\
if [[ -a ~/t/hello.py ]];thenecho "存在文件";rm -f ~/t/hello.pyfi;
3、测试效果如下图所示
用-e运算符判断,例如
if [ -e $FILE ]then rm -f $FILEfi