Linux rmdir Commands Use the detailed _linux

Source: Internet
Author: User
Tags parent directory

This article study linux command: RmDir command. RmDir is a commonly used command that has the function of deleting an empty directory and must be empty before a directory is deleted. (Note that the Rm-r dir command can replace RmDir, but it is risky.) When you delete a directory, you must also have write permissions to the parent directory.

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

2. Command function:
This command deletes one or more subdirectory entries from one directory, and must also have write permissions to the parent directory when deleting a directory.

3. Command parameters:
-P recursively deletes the directory dirname, which is also deleted when the subdirectory is deleted and its parent directory is empty. If the entire path is deleted or some of the paths are retained for some reason, the system displays the appropriate information on the standard output.
-V,--verbose display instruction execution procedure

4. Command instance :
instance one: rmdir cannot delete non-empty directories
command:
RmDir doc
Output:

Copy Code code as follows:

[Root@localhost scf]# Tree
.
|--Bin
|-|-doc
| |--Info
| '--product
|--Lib
|--Logs
| |--Info
| '--product
'--Service
'--Deploy
|--Info
'--product

Directories, 0 files
[Root@localhost scf]# rmdir doc
Rmdir:doc: 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

Ten directories, 0 files

Description
RmDir Directory name command cannot delete non-empty directory directly

Instance 2:rmdir-p when a subdirectory is deleted and makes it an empty directory, it is deleted by the way
Command:
Rmdir-p logs
Output:

Copy Code code as follows:

[Root@localhost scf]# Tree
.
|--Bin
|-|-doc
|--Lib
|--Logs
| '--product
'--Service
'--Deploy
|--Info
'--product

Ten 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

Summary:
This command is used to delete an empty directory, and an error occurs if the directory is not empty. After you can use RM to delete a file in a directory, use RmDir to delete the directory. You can also use RM-RF instead of the rmdir command. This is a very simple command.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.