How to determine whether a file or directory exists through an if statement in Linux

王林
Release: 2019-12-18 10:42:04
Original
4938 people have browsed it

How to determine whether a file or directory exists through an if statement in Linux

Directory judgment:

    path="/home"
    #if [ ! -d ${path} ];then
    if [ -d ${path} ];then
        echo dir ${path} exist!
    else
        echo dir ${path} not exist!
    fi
Copy after login

Free learning video tutorial sharing: linux video tutorial

File judgment:

    file="/home/log.txt"
    if [ -f ${file} ];then
        echo file ${file} exist!
    else
        echo file ${file} not exist!
    fi
Copy after login

Recommended related articles and tutorials: linux tutorial

The above is the detailed content of How to determine whether a file or directory exists through an if statement in Linux. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!