Linux Terminal Command: rmdir
The rmdir command is an essential tool in Foundations & Navigation. In this tutorial, we will explore what rmdir does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.
Concept & Explanation
The rmdir command deletes directories only if they do not contain any files or subdirectories. This makes it a safe tool that prevents accidental data loss.
Common Options & Syntax
rmdir [options] [arguments]
Here are the most common flags used with rmdir:
- Simple Usage: Basic default commands.
- Detailed View: Shows diagnostic information.
- Advanced Actions: Can chain parameters for scripting.
1. Interactive Example (Simple)
Here is how most people run the command:
# Example
rmdir empty_folder
What it does: Removes the directory ’empty_folder’ if it is completely empty.
2. Power-User Example (Advanced)
For scripting and advanced diagnostics, use this configuration:
# Advanced
rmdir -p parent/child/grandchild
What it does: Removes the grandchild directory and recursively removes its parents (child, parent) if they become empty after deletion.
⚙️ Warning & Common Pitfalls
[!WARNING] If a directory contains even hidden files (like
.DS_Storeor.git),rmdirwill fail. Userm -rfif you intend to remove non-empty folders.
🔗 Related Commands
Here are some related posts on cli_tty1 you might want to check out:
- rm : Remove files or directories.