Linux uses if to determine whether a file exists

angryTom
Release: 2019-11-06 15:12:52
Original
5915 people have browsed it

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
Copy after login

2. Grant execution permission to the script

chmod +x a.sh
Copy after login

3. Run the script

./a.sh
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!