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 to check whether a file exists in Linux

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

Share

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

There are two ways for Linux to see if a file exists: 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

Shell is a program written in C language, which is a bridge for users to use Linux. Shell is both a command language and a programming language. Shell is an application that provides an interface through which users access the services of the operating system kernel.

(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.sh

#! / bin/bashif [- e / temp/test.log]; then / / here is the judgment statement.-e means that if the comparison result is true, there is an echo "file exists and the" elseecho "file does not exist" fi "

Save exit

Execute:

Sh t.sh

These are the details of Linux's method to check whether the file exists. For more information, please follow other related articles!

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