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

Implementation of MySQL multi-version concurrency control MVCC

Transaction isolation level settings set global t...

How to use the WeChat Mini Program lottery component

It is provided in the form of WeChat components. ...

Implementation of fuzzy query like%% in MySQL

1, %: represents any 0 or more characters. It can...

Implementing simple chat room dialogue based on websocket

This article shares the specific code for impleme...

Implementation of single process control of Linux C background service program

introduce Usually a background server program mus...

Solution for Tomcat to place configuration files externally

question When we are developing normally, if we w...

How to use mysqladmin to get the current TPS and QPS of a MySQL instance

mysqladmin is an official mysql client program th...

Jenkins Docker static agent node build process

A static node is fixed on a machine and is starte...

View MySQL installation information under Linux server

View the installation information of mysql: #ps -...

Complete step-by-step record of MySQL 8.0.26 installation and uninstallation

Table of contents Preface 1. Installation 1. Down...

Solution to running out of MySQL's auto-increment ID (primary key)

There are many types of auto-increment IDs used i...

Linux system dual network card binding configuration implementation

System version [root@ ~]# cat /etc/redhat-release...

Native JS to implement real-time clock

Share a real-time clock effect implemented with n...

Detailed explanation of the production principle of jQuery breathing carousel

This article shares the specific process of the j...