How to use the rmdir command under Linux

PHPz
Release: 2023-05-11 16:52:06
forward
1855 people have browsed it

rmdir is a commonly used command. The function of this command is to delete empty directories. A directory must be empty before it is deleted. (Note that the rm -r dir command can replace rmdir, but it is very dangerous.) When deleting a directory, you must also have write permissions on the parent directory.

1. Command format:
rmdir [option]... Directory...

2. Command function:
This command deletes one or more subdirectory items from a directory. When deleting a directory, you must also have write permissions on the parent directory.

3. Command parameters:
-p Recursively delete the directory dirname. When the subdirectory is deleted and its parent directory is empty, it will also be deleted. If the entire path is deleted or part of the path is retained for some reason, the system displays the appropriate information on standard output.
-v, --verbose Display the command execution process
4. Command example:
Example 1: rmdir cannot delete non-empty directories
Command:
rmdir doc
Output:

Copy code The code is as follows:

[root@localhost scf]# tree
.
|-- bin
|-- doc
| |-- info
| `-- product
|-- lib
|-- logs
| |-- info
| `-- product
`-- service
`-- deploy
|-- info
`-- product

12 directories, 0 files
[root@localhost scf]# rmdir doc
rmdir: doc: The directory is not empty
[root@localhost scf]# rmdir doc/info
[root@localhost scf]# rmdir doc/product
[root@localhost scf]# tree
.
|-- bin
|-- doc
|-- lib
|-- logs
| |-- info
| `-- product
`-- service
`-- deploy
|-- info
`-- product

10 directories, 0 files

Note:
rmdir directory name command cannot directly delete non-empty directories

Example 2: rmdir -p when a subdirectory is deleted If you later make it an empty directory, delete it as well
Command:
rmdir -p logs
Output:

Copy code The code is as follows:


[root@localhost scf]# tree
.
|-- bin
|-- doc
|-- lib
|-- logs
| `-- product
`-- service
                                                                                                                                                                                                  p logs
rmdir: logs: directory is not empty
[root@localhost scf]# tree
.
|-- bin
|-- doc
|-- lib
|-- logs
| `-- product
`-- service
`-- deploy
                                                                                                                                                                                                           been not not not been been been been been been been had been been been been made. 0 files
[root@localhost scf]# rmdir -p logs/product
[root@localhost scf]# tree
.
|-- bin
|-- doc
|-- lib
`-- service
`-- deploy
|-- info
`-- product

7 directories, 0 files

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

Related labels:
source:yisu.com
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