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