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

How does linux check whether a file exists?

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

Share

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

How does linux check whether the file exists? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

There are two check methods: the find command or the shell script.

1. Find command

(1) find is a general method for finding files under linux.

(2) find syntax: find [specify lookup directory] [lookup rules] [action to be executed after lookup]

(3) for example: find / tmp-name wa*-type l looks under / tmp for a file whose name begins with wa and whose type is symbolic link. If you find it, it means it exists.

2. Shell script

(1) automatic discrimination is often needed in the automatic processing of files. The following script determines whether the test.log exists, and if it exists, it shows that the file exists, otherwise the display file does not exist.

(2) example: edit a script to determine whether the file exists.

Vi t. Shrunken bind temp/test.log Binder Bashif [- e / temp/test.log]; here is the judgment statement,-e means that if the comparison result is true, there is an echo "file exists" elseecho file does not exist "fi"

Save exit

Execute:

This is the answer to sh t.sh 's question about how to check whether the file exists in linux. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

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