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 replace all tags in html text

(?i) means do not match case. Replace all uppercas...

HTML drawing user registration page

This article shares the specific implementation c...

Python writes output to csv operation

As shown below: def test_write(self): fields=[] f...

How to build a MySQL PXC cluster

Table of contents 1. Introduction to PXC 1.1 Intr...

js to realize web message board function

This article example shares the specific code of ...

HTML pop-up div is very useful to realize mobile centering

Copy code The code is as follows: <!DOCTYPE ht...

Detailed installation and uninstallation tutorial for MySQL 8.0.12

1. Installation steps for MySQL 8.0.12 version. 1...

Linux common basic commands and usage

This article uses examples to illustrate common b...

How to install openssh from source code in centos 7

Environment: CentOS 7.1.1503 Minimum Installation...

Windows Server 2008 R2 Multi-User Remote Desktop Connection Licensing

At work, we often need remote servers and often e...

Solution to forgetting mysql password under linux

The problem is as follows: I entered the command ...

Use a few interview questions to look at the JavaScript execution mechanism

Table of contents Previous words Synchronous and ...