Home > Operation and Maintenance > Linux Operation and Maintenance > Does Linux have a function to determine the existence of a file?

Does Linux have a function to determine the existence of a file?

WBOY
Release: 2022-05-23 18:12:05
Original
2483 people have browsed it

Linux has a function to determine whether a file exists; this function is the wildcard function of the makefile. The wildcard function can match the file list. If there is no file matching the specified pattern, the function will return empty, and the syntax is "$(wildcard PATTERN...)".

Does Linux have a function to determine the existence of a file?

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

Does Linux have a function to determine the existence of a file?

Linux has a function to determine the existence of a file

Use the wildcard function of makefile

ifneq ($(wildcard FILE,)
#文件存在
endif
Copy after login

$(wildcard FILE) means the file expansion matching the FILE file under the current path.

Assume that a.c and b.c exist in the current path, then execute src=$(wildcard *.c), the value of src will be a.c b.c;

If you do not use wildcards, such as src=$ (wildcard c.c); then you need to expand the file named c.c under the current path. Because the file does not exist under the current path, src is an empty string.

Examples are as follows:

Use the above two methods to determine whether the depend.mk file in the obj folder exists. If it exists, create a.c and b.c files.

The makefile written is as follows:

OBJ_DIR=obj
fileNames = $(wildcard $(OBJ_DIR)/depend.mk)
all:
@echo "this is all "
@echo ${fileNames}
@if [ -e $(OBJ_DIR)/depend.mk ]; then touch b.c; fi
ifneq ($(wildcard $(OBJ_DIR)/depend.mk),)
touch a.c
endif
Copy after login

After execution, a.c and b.c were successfully created.

Does Linux have a function to determine the existence of a file?

Recommended learning: Linux video tutorial

The above is the detailed content of Does Linux have a function to determine the existence of a file?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template