Linux command learning summary of the rmdir command

  • 2020-05-15 02:35:03
  • OfStack

Command summary:

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

Command syntax:

rmdir [OPTION]... DIRECTORY...

Command parameters:

参数

长参数

描叙

--ignore-fail-on-non-empty

忽略任何应目录里面有数据文件而造成的错误

-p

--parents

递归删除目录

-v

--verbose

显示命令执行的详细信息

--help

显示命令在线帮助

--version

显示命令版本信息

Use examples:

1: view the help information for 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 < bug-coreutils@gnu.org > .

You can also view the rmdir document information using the following command

[root@DB-Server ~]# man rmdir

2: use rmdir to delete empty directories

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

[root@DB-Server ~]# ls /root/kerry/file1[root@DB-Server ~]# rmdir kerryrmdir: kerry: Directory not empty[root@DB-Server ~]# rm -f /root/kerry/*[root@DB-Server ~]# rmdir kerry

3: display the detailed information when the command is executed

[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 the empty directory tmp under the kerry directory, then the 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 having 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/


Related articles: