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

Summary of usage of Linux command rmdir

巴扎黑
Release: 2017-09-04 14:15:27
Original
3682 people have browsed it

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
Copy after login

Report bugs to .

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

[root@testServ ~]# man rmdir
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

2 directories, 0 files

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

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/
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template