rmdir
Quick Reference
Command Name:
rmdir
Category:
file management
Platform:
linux
Basic Usage:
Common Use Cases
- 1
Directory removal
Remove empty directories from the filesystem
- 2
Cleanup
Remove unnecessary or temporary directories
- 3
Scripting
Use in shell scripts to remove directories programmatically
- 4
File management
Manage directories and files in the filesystem
Syntax
rmdir [OPTION]... DIRECTORY...
Options
Option | Description |
---|---|
--ignore-fail-on-non-empty | Ignore each failure that is solely because a directory is non-empty |
-p, --parents | Remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is similar to 'rmdir a/b/c a/b a' |
-v, --verbose | Output a diagnostic for every directory processed |
--help | Display help information and exit |
--version | Output version information and exit |
Examples
How to Use These Examples
The examples below show common ways to use the rmdir
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
rmdir documents
Removes the empty directory named documents from the current working directory. This will fail if the directory contains any files or subdirectories.
rmdir dir1 dir2 dir3
Removes multiple empty directories at once. This example removes three empty directories named dir1, dir2, and dir3.
rmdir -p parent/child/grandchild
Removes directories and their parents recursively. The -p option removes the specified directory and then attempts to remove each parent directory if they become empty. In this example, it will remove grandchild, then child, and finally parent if each becomes empty after the previous removal.
rmdir --ignore-fail-on-non-empty test_dir
Attempts to remove a directory, but doesn't display an error if the directory contains files. This is useful in scripts where you want to attempt a removal but continue regardless of the outcome.
Advanced Examples:
rmdir -pv project/src/lib
Removes nested directories with verbose output. The -v option displays a message for each directory processed. Combined with -p, it will show the removal of lib, then src, then project (if each becomes empty).
rmdir "Old Project Files"
Removes a directory with spaces in its name. When directory names contain spaces, they should be enclosed in quotes to be properly interpreted.