Linux command learning (6): rmdir

Learn about the commands in linux today: rmdir command . 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 be used in place of rmdir, but it is very dangerous.) When deleting a directory, you must also have write permission to the parent directory.

 

-----------------------------------------------------------------------------------------

 

 

1. Command format:

rmdir [options]... directory...

2. Command function:

This command removes one or more subdirectory entries from a directory, and must also have write permission to the parent directory when deleting a directory . 

3. Command parameters:

-p deletes the directory dirname recursively. When the parent directory is empty after the subdirectory is deleted, it is also deleted together. If the entire path is removed or part of the path remains for some reason, the system displays the appropriate information . 

-v, --verbose   show command execution process 

 

4. Command example:

 

------------------------------------------------------------------------------------

 

 

Example 1: rmdir  cannot delete non-empty directories

Order:

     rmdir doc

output:

[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: directory 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

 

illustrate:

The rmdir  directory name  command cannot directly delete non-empty directories

 

 

 

Example 2: rmdir -p  When the subdirectory is deleted and it becomes an empty directory, it will be deleted by the way 

Order:

rmdir -p logs

输出:

[root@localhost scf]# tree

.

|-- bin

|-- doc

|-- lib

|-- logs

|   `-- product

`-- service

    `-- deploy

        |-- info

        `-- product

 

10 directories, 0 files

[root@localhost scf]# rmdir -p logs

rmdir: logs: 目录非空

[root@localhost scf]# tree

.

|-- bin

|-- doc

|-- lib

|-- logs

|   `-- product

`-- service

    `-- deploy

        |-- info

        `-- product

 

9 directories, 0 files

[root@localhost scf]# rmdir -p logs/product

[root@localhost scf]# tree

.

|-- bin

|-- doc

|-- lib

`-- service

`-- deploy

        |-- info

        `-- product

 

7 directories, 0 files

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327073516&siteId=291194637