linux uses if to determine whether a file exists
We can use the Linux shell to determine whether a file exists. Let’s take a look.
1. Create a new a.sh file
#这里的-f参数判断/home/abc.log是否存在 if [ -f "/home/abc.log" ]; then echo "文件存在" else echo "文件不存在" fi
2. Grant execution permission to the script
chmod +x a.sh
3. Run the script
./a.sh
Recommended: linux introductory tutorial
The above is the detailed content of Linux uses if to determine whether a file exists. For more information, please follow other related articles on the PHP Chinese website!