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

Linux determines whether a file exists

angryTom
angryTomOriginal
2019-11-05 10:39:0912298browse

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文件信息,不存在则报错

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

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!

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