Home > Article > Operation and Maintenance > Linux determines whether a file exists
##linux determines whether the file exists
1. Use the ls command to determinels -l /home/admin/test.txt # 查看/home/admin/目录下test.txt文件信息,不存在则报错2. Use find to search and judge.
find /home -name "test.txt" # 在/home目录及其子目录下查找test.txt文件,不存在则无输出3. Use shell script to judge. Save it as abc.sh and run it with sh abc.sh.
#文件存在则删除 if [ ! -f "/data/test.txt" ];then echo "文件不存在" else echo "文件存在" fiRecommended learning:
The above is the detailed content of Linux determines whether a file exists. For more information, please follow other related articles on the PHP Chinese website!