Home  >  Article  >  Operation and Maintenance  >  How to use shell to determine whether a file or directory exists in Linux

How to use shell to determine whether a file or directory exists in Linux

王林
王林Original
2020-02-14 14:11:483613browse

How to use shell to determine whether a file or directory exists in Linux

Judgment directory:

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

Video tutorial recommendation: linux video tutorial

Judgment file:

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

Recommended related articles and tutorials: linux tutorial

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

Statement:
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