Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of judging the existence of File in linux

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report