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


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:


long parameter



Ignore any errors caused by data files in the directory



Delete directory recursively



Display detailed information of command execution


Display command online help


Example of use:

1: View the help information of the rmdir command

[[email protected] ~]# 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

[[email protected] ~] # man rmdir

2: Use rmdir to delete an empty directory

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

[ [email protected] ~]# ls /root/kerry/file1[[email protected] ~]# rmdir kerry rmdir: kerry: directory not empty[[email protected] ~]# rm -f /root/kerry/*[[email protected] ~]# rmdir kerry

3: display Detailed information during command execution

[[email protected] ~]# mkdir test1 test2 test3[[email protected] ~]# lsanaconda-ks.cfg desktop install.log install. log.syslog test1 test2 test3[[email protected] ~]# 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

[[email protected] ~]# mkdir -p kerry/tmp/test[[email protected] ~]# tree kerrykerry`-- tmp `-- test 2 directories, 0 files[[email protected] ~]# rmdir -p kerry/tmp/test

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

[[email protected] ~]# mkdir kerry [root @db-server ~]# cd kerry [[email protected] kerry]# touch file1 [[email protected] kerry]# cd .. [[email protected] ~]# 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