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

Writing and understanding of arrow functions and this in JS

Table of contents Preface 1. How to write functio...

The pitfall of MySQL numeric type auto-increment

When designing table structures, numeric types ar...

Vue3+TypeScript implements a complete example of a recursive menu component

Table of contents Preface need accomplish First R...

In-depth explanation of Vue multi-select list component

A Multi-Select is a UI element that lists all opt...

Solution to Linux not supporting all commands

What should I do if Linux does not support all co...

Solve MySQL deadlock routine by updating different indexes

The previous articles introduced how to debug loc...

MySQL partition table is classified by month

Table of contents Create a table View the databas...

Tutorial on installing Microsoft TrueType fonts on Ubuntu-based distributions

If you open some Microsoft documents with LibreOf...

What to do if you forget the initial password of MySQL on MAC

The method to solve the problem of forgetting the...

CSS achieves highly adaptive full screen

When writing my own demo, I want to use display:f...

Zabbix's psk encryption combined with zabbix_get value

Since Zabbix version 3.0, it has supported encryp...

Getting Started with Front-End Vue Unit Testing

Table of contents 1. Why do we need unit testing?...

CSS 3.0 text hover jump special effects code

Here is a text hovering and jumping effect implem...