Home > Operation and Maintenance > Linux Operation and Maintenance > Linux determines whether a file exists

Linux determines whether a file exists

angryTom
Release: 2019-11-05 10:39:09
Original
12424 people have browsed it

Linux determines whether a file exists

##linux determines whether the file exists

1. Use the ls command to determine


ls -l /home/admin/test.txt # 查看/home/admin/目录下test.txt文件信息,不存在则报错
Copy after login

2. Use find to search and judge.

find /home -name "test.txt" # 在/home目录及其子目录下查找test.txt文件,不存在则无输出
Copy after login

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 "文件存在"
fi
Copy after login

Recommended learning:

linux system tutorial

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!

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