"; 2. Use the bash shell command to check, the syntax is "[-f file path] && echo "found" || echo "not found""."> How to check if a file exists in linux-Linux Operation and Maintenance-php.cn

How to check if a file exists in linux

青灯夜游
Release: 2021-12-02 17:39:29
Original
25703 people have browsed it

Linux method to check whether the file exists: 1. Use the test command to check, the syntax "test -e "; 2. Use the bash shell command to check, the syntax "[-f file path ] && echo "found" || echo "not found"".

How to check if a file exists in linux

The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

Linux checks whether the file exists

1. test command

It is often used to test conditional expressions, using The command istest -e .

2. Use bash shell to check

Assume we have the file directory/home/benben/go_projectand the file/home/benben/go_project/test.txt, below we use the bash shell command to check whether this directory and file exist.

  • Check the directory and execute the command[-d /home/benben/go_project ] && echo "found" || echo "not found"or[-d . /go_project ] && echo "found" || echo "not found".
  • Check the file and execute the command[-f /home/benben/go_project/test.txt] && echo "found" || echo "not found"or[-f ./test.txt ] && echo "found" || echo "not found"

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of How to check if a file exists in linux. 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
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!