How to use rmdir command guide in Linux

  

We all know that the rm command in the Linux command is mainly used to delete files, then what is the role of the rmdir command? The following small series will introduce you to the main functions of the rmdir command in the Linux command.

rmdir is commonly used commands, functions of the command is to delete empty directories, before a directory is deleted must be empty. (Note that the rm - r dir command can be used instead of rmdir, but it is very dangerous.) When you delete a directory, you must also have write access to the parent directory.

1. Command format:

rmdir [options]. . . table of Contents. . .

2. Command Function:

This command deletes one or more subdirectory entries from a directory. When deleting a directory, it must also have write access to the parent directory.

3. Command parameters:

- p Recursively deletes the directory dirname. When the parent directory is empty after the subdirectory is deleted, it is also deleted. If the entire path is deleted or part of the path is reserved for some reason, the system displays the corresponding information on the standard output.

-v, --verbose Display instruction execution

4. Command Example:

Instance 1: rmdir cannot delete non-empty directories

Command:

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 Non-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

Description:

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

Instance 2: rmdir -p When the subdirectory is deleted and made it empty, then delete the

command:

rmdir -p logs

Output:

[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 : Directory is not empty

[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

The above is the role of the Linux rmdir command. This command can only delete empty directories and cannot be deleted. A directory with hidden or system files, so be careful when using it.

Copyright © Windows knowledge All Rights Reserved