Home > Operation and Maintenance > Linux Operation and Maintenance > How to use if in Linux to determine whether a directory exists

How to use if in Linux to determine whether a directory exists

angryTom
Release: 2020-03-10 16:12:15
Original
3278 people have browsed it

How to use if in Linux to determine whether a directory exists

How to use if in Linux to determine whether a directory exists

The method is as follows:

1. Script How to use if to determine whether a directory exists

#! /bin/bash
if [ -d "c" ];then
    echo "目录c存在"
 else
     echo "目录不存在"
fi
Copy after login

Recommendation:Linux Tutorial Column

2. Simple writing method

#! /bin/bash
[ -d "c" ] && echo "目录c存在"
# 或者
[ -d "d" ] || echo "目录d不存在"
Copy after login

More judgment formats are as follows:

-e filename 如果 filename存在,则为真 
-d filename 如果 filename为目录,则为真 
-f filename 如果 filename为常规文件,则为真 
-L filename 如果 filename为符号链接,则为真 
-r filename 如果 filename可读,则为真 
-w filename 如果 filename可写,则为真 
-x filename 如果 filename可执行,则为真 
-s filename 如果文件长度不为0,则为真 
-h filename 如果文件是软链接,则为真
Copy after login

Related recommendations:

Linux video tutorial, learning address: https://www.php.cn /course/list/33.html

The above is the detailed content of How to use if in Linux to determine whether a directory exists. 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
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template