Linux uses if to determine whether a directory exists.

Linux uses if to determine whether a directory exists.

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

Here’s how:

1. How to use if in the script to determine whether a directory exists

#!/bin/bash
if [ -d "c" ];then
  echo "directory c exists"
 else
   echo "directory does not exist"
fi

2. Simple writing

#!/bin/bash
[ -d "c" ] && echo "Directory c exists"
# or [ -d "d" ] || echo "Directory d does not exist"

More judgment formats are as follows:

-e filename True if filename exists

-d filename True if filename is a directory

-f filename True if filename is a regular file.

-L filename True if filename is a symbolic link

-r filename True if filename is readable

-w filename True if filename is writable

-x filename True if filename is executable

-s filename True if filename is not zero length

-h filename True if filename is a soft link

This concludes this article on how to use if in Linux to determine whether a directory exists. For more information on how to use if in Linux to determine whether a directory exists, please search for previous articles on 123WORDPRESS.COM or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Linux file/directory permissions and ownership management
  • How to change the MySQL database directory location under Linux (CentOS) system
  • Deleting files with spaces in Linux (not directories)
  • Summary of Linux file directory management commands

<<:  Several common methods of sending requests using axios in React

>>:  Detailed explanation of how to connect Java to Mysql version 8.0.18

Recommend

HTML table tag tutorial (31): cell width and height attributes WIDTH, HEIGHT

By default, the width and height of the cell are ...

Solution to inconsistent display of cursor size in input box

The cursor size in the input box is inconsistent T...

In-depth analysis of HTML semantics and its related front-end frameworks

About semantics Semantics is the study of the rel...

Summary of three rules for React state management

Table of contents Preface No.1 A focus No.2 Extra...

Common front-end JavaScript method encapsulation

Table of contents 1. Enter a value and return its...

Typora code block color matching and title serial number implementation code

Effect: The title has its own serial number, the ...

Install CentOS 7 on VMware14 Graphic Tutorial

Introduction to CentOS CentOS is an enterprise-cl...

Implementation of MySQL multi-version concurrency control MVCC

Transaction isolation level settings set global t...

Docker Machine in-depth explanation

Differences between Docker and Docker Machine Doc...

Detailed installation and configuration of MySql on Mac

1. Download and install Download the community ed...

Improvements to the web server to improve website performance

<br />In the first section of this series, w...