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 find out if a directory or file exists

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

The main content of this article is to explain "linux how to find the existence of directories or files", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "linux how to find out whether a directory or file exists".

Methods: 1, the use of find command, syntax for "find directory or file search rules"; 2, the use of shell script, syntax for "if [- e directory or file]; then echo" file exists "else echo" file does not exist "fi".

The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How does linux find out if a directory or file exists?

There are two ways: find command or 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"

Examples are as follows:

At this point, I believe you have a deeper understanding of "linux how to find the existence of directories or files". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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