The method of judging the existence of File in linux
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!