Get the App
SLTechnology News&Howtos  ›  Servers  › 

The method of judging the existence of File in linux

Shulou Source: shulou.com Published: 2022-06-03 06:30:10 10月04日 Update

This article mainly introduces in detail the method of judging the existence of files in linux. The sample code in this article is very detailed and has a certain reference value. Interested friends can refer to it.

Linux determines whether the file exists or not

1. Use the ls command to judge

Ls-l / home/admin/test.txt # View the test.txt file information in the / home/admin/ directory. If it does not exist, an error will be reported.

2. Use find to find and judge

Find / home-name "test.txt" # look for the test.txt file in the / home directory and its subdirectories, no output if it does not exist

3. Use shell script to judge

Save as abc.sh and run using sh abc.sh.

# delete if [!-f "/ data/test.txt"] if the file exists; then echo "file does not exist" else echo "file exists" fi

The above is a brief introduction to the method of judging the existence of a file in linux, of course, the detailed use of the above differences still have to be used by everyone to understand. If you want to know more, welcome to follow the industry information channel!

Tags: Files methods directories references different abbreviations code value information interests commands subcategories subdirectories guys buddies that is more examples articles scripts Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi Microsoft Shulou Tech Info Linux