Linux – rmdir Command

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.



Tutorials dojo strip

Initial Example

Using rmdir to remove an empty directory called OldFolder:

rmdir OldFolder




RMDIR Parameters

ParameterDescription
--ignore-fail-on-non-emptySkip errors when trying to remove directories that are not empty
-p, --parentsRemove a directory and its parent directories, e.g., rmdir -p a/b removes a/b and a
-v, --verboseDisplay a message for each directory that is being removed
--helpShow help information and exit
--versionDisplay 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




Linux Playground

Scroll to Top