The rmdir
command stands for “remove directory.” It is used to delete empty directories from the file system. Unlike the rm
command, which can delete files and directories regardless of their contents, rmdir
only removes directories that are empty.
Initial Example
Using rmdir
to remove an empty directory called OldFolder
:
rmdir OldFolder
RMDIR Parameters
Parameter | Description |
---|---|
--ignore-fail-on-non-empty | Skip errors when trying to remove directories that are not empty |
-p, --parents | Remove a directory and its parent directories, e.g., rmdir -p a/b removes a/b and a |
-v, --verbose | Display a message for each directory that is being removed |
--help | Show help information and exit |
--version | Display version information and exit |
Examples
1. Remove a Single Empty Directory
To remove an empty directory:
rmdir EmptyFolder
2. Remove Multiple Empty Directories
To remove multiple empty directories at once, specify their names separated by spaces:
rmdir Dir1 Dir2 Dir3
3. Remove Nested Empty Directories
To remove a directory and its empty parent directories, use the -p
option:
rmdir -p ParentDir/ChildDir/GrandChildDir