What is the function of the Linux rmdir command and how to use it

02-16-2023

The editor of this article will introduce in detail what the Linux rmdir command does and how to use it. The content is detailed, the steps are clear, and the details are handled properly. I hope this article on what the Linux rmdir command does and how to use it can help you solve your doubts , Let’s follow the editor’s ideas and slowly deepen, let’s learn new knowledge together.

Command introduction:

The rmdir command is used to delete an empty directory. If the directory is not empty, an error will occur. After you can use rm to delete the files in the directory, use rmdir to delete the directory. You can also use rm -rf instead of the rmdir command. This is a very simple command.

Command syntax:

rmdir [option]... directory...

Command parameter:

parameter

long parameter

Description


--ignore-fail-on-non-empty

Ignore any errors caused by data files in the directory

-p

--parents

Delete directory recursively

-v

--verbose

Display detailed information of command execution


--help

Display command online help


--version


Example of use:

1: View the help information of the rmdir command

[root@db-server ~]# rmdir --helpusage: rmdir [option]... directory...remove the directory(ies), if they are empty. --ignore-fail-on-non-empty ignore each failure that is solely because a directory is non-empty -p, --parents remove directory and its ancestors. e.g., ` rmdir -p a/b/c' is similar to `rmdir a/b/c a/b a'. -v, --verbose output a diagnostic for every directory processed --help display this help and exit --version output version information and exit report bugs to.

You can also use the following command to view rmdir file information

[root@db-server ~] # man rmdir

2: Use rmdir to delete an empty directory

If the directory is not empty, an error message will appear.

[ root@db-server ~]# ls /root/kerry/file1[root@db-server ~]# rmdir kerry rmdir: kerry: directory not empty[root@db-server ~]# rm -f /root/kerry/*[root@db-server ~]# rmdir kerry

3: display Detailed information during command execution

[root@db-server ~]# mkdir test1 test2 test3[root@db-server ~]# lsanaconda-ks.cfg desktop install.log install. log.syslog test1 test2 test3[root@db-server ~]# rmdir -v test1 test2 test3rmdir: removing directory, test1rmdir: removing directory, test2rmdir: removing directory, test3

4: Recursively delete the directory, as shown below, first create the directory kerry, create an empty directory tmp under the kerry directory, and then create an empty directory test

[root@db-server ~]# mkdir -p kerry/tmp/test[root@db-server ~]# tree kerrykerry`-- tmp `-- test 2 directories, 0 files[root@db-server ~]# rmdir -p kerry/tmp/test

5: Ignore any errors caused by data files in the directory

[root@db-server ~]# mkdir kerry [root @db-server ~]# cd kerry [root@db-server kerry]# touch file1 [root@db-server kerry]# cd .. [root@db-server ~]# rmdir --ignore-fail-on- non-empty kerry/


Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us