Home >Operation and Maintenance >Linux Operation and Maintenance >Summary of usage of Linux command rmdir

Summary of usage of Linux command rmdir

巴扎黑
巴扎黑Original
2017-09-04 14:15:273680browse

Command introduction:

This command is used to delete empty directories. If the directory is not empty, an error will occur. You can use rm to delete the files in the directory and then 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 parameters:

Parameters

Long parameters

Description

--ignore-fail-on-non-empty

Ignore any data in the directory Error caused by file

-p

--parents

Recursively delete directory

-v

--verbose

Display detailed information about command execution

--help

Display command online help

--version

Display command version information

Usage example:

1: View the help information of the rmdir command

[root@testServ ~]# rmdir --help
Usage: 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 a78933fb2a4ec664f95b7539a7317bf7.

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

[root@testServ ~]# man rmdir

2: Use rmdir to delete the empty directory

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

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

3: Display detailed information when the command is executed

[root@testServ ~]# mkdir test1  test2 test3
[root@testServ ~]# ls
anaconda-ks.cfg  Desktop  install.log  install.log.syslog  test1  test2  test3
[root@testServ ~]# rmdir -v test1  test2 test3
rmdir: removing directory, test1
rmdir: removing directory, test2
rmdir: removing directory, test3

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

 
[root@testServ ~]# mkdir -p kerry/tmp/test
[root@testServ ~]# tree kerry
kerry
`-- tmp
    `-- test

2 directories, 0 files

[root@testServ ~]# rmdir -p kerry/tmp/test

5: Ignore any data files in the directory. Error caused by

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

The above is the detailed content of Summary of usage of Linux command rmdir. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn