Home  >  Article  >  Operation and Maintenance  >  Linux uses if to determine whether a file exists

Linux uses if to determine whether a file exists

angryTom
angryTomOriginal
2019-11-06 15:12:525871browse

Linux uses if to determine whether a file exists

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How about linux systemNext article:How about linux system