Linux Command: rmdir command to learn and use, linuxrmdir
Today, I want to learn about the command rmdir in linux. Rmdir is a common command used to delete an empty directory. A directory must be empty before it is deleted. (Note that the rm-rdir command can replace rmdir, but it is highly risky .) When deleting a directory, you must also have the write permission on the parent directory.
1. Command Format:
Rmdir [Option]… Directory...
2. command functions:
This command deletes one or more sub-directory items from a directory. When deleting a directory, you must have the write permission on the parent directory.
3. command parameters:
-P recursively deletes the directory dirname. When the subdirectory is deleted and its parent directory is empty, it is also deleted. If the entire path is deleted or some paths are retained for some reason, the system displays the corresponding information on the standard output.
-V and-verbose display Command Execution Process
4. Command instance:
Instance 1: rmdir cannot delete non-empty directories
Command:
Rmdirdoc
Output:
[Root @ localhostscf] # tree
.
|-Bin
|-Doc
|-Info
| '-Product
|-Lib
|-Logs
|-Info
| '-Product
'-Service
'-Deploy
|-Info
'-Product
12 directories, 0 files
[Root @ localhostscf] # rmdirdoc
Rmdir: doc: the directory is not empty.
[Root @ localhostscf] # rmdirdoc/info
[Root @ localhostscf] # rmdirdoc/product
[Root @ localhostscf] # tree
.
|-Bin
|-Doc
|-Lib
|-Logs
|-Info
| '-Product
'-Service
'-Deploy
|-Info
'-Product
10 directories, 0 files
Note:
The rmdir directory name command cannot directly Delete non-empty directories.
Instance 2: rmdir-p when the subdirectory is deleted and becomes an empty directory, it will be deleted along the way.
Command:
Rmdir-plogs
Output:
[Root @ localhostscf] # tree
.
|-Bin
|-Doc
|-Lib
|-Logs
| '-Product
'-Service
'-Deploy
|-Info
'-Product
10 directories, 0 files
[Root @ localhostscf] # rmdir-plogs
Rmdir: logs: the directory is not empty.
[Root @ localhostscf] # tree
.
|-Bin
|-Doc
|-Lib
|-Logs
| '-Product
'-Service
'-Deploy
|-Info
'-Product
9 directories, 0 files
[Root @ localhostscf] # rmdir-plogs/product
[Root @ localhostscf] # tree
.
|-Bin
|-Doc
|-Lib
'-Service
'-Deploy
|-Info
'-Product
7 directories, 0 files