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

How to set up automatic daily database backup in Linux

This article takes Centos7.6 system and Oracle11g...

CSS3 click button circular progress tick effect implementation code

Table of contents 8. CSS3 click button circular p...

6 interesting tips for setting CSS background images

Background-image is probably one of those CSS pro...

Detailed explanation of Nginx forwarding socket port configuration

Common scenarios for Nginx forwarding socket port...

A brief discussion on the use of GROUP BY and HAVING in SQL statements

Before introducing the GROUP BY and HAVING clause...

Detailed explanation of viewing and setting file permissions on Mac

Preface To modify file permissions in the termina...

Method example of safely getting deep objects of Object in Js

Table of contents Preface text parameter example ...

Vue Router loads different components according to background data

Table of contents Requirements encountered in act...

Detailed steps to install mysql5.7.18 on Mac

1. Tools We need two tools now: MySQL server (mys...

MySQL quickly inserts 100 million test data

Table of contents 1. Create a table 1.1 Create te...

The difference between html block-level tags and inline tags

1. Block-level element: refers to the ability to e...

MySQL log system detailed information sharing

Anyone who has worked on a large system knows tha...