rm — Delete Files and Directories (No Recycle Bin!)
rm permanently deletes files — there's no Recycle Bin. Learn safe deletion practices, when rm -rf is appropriate, and how to protect yourself from accidents.
rm deletes files and directories permanently. There is no Recycle Bin, no Trash folder, no Undo. Once it's gone, recovering it requires specialised disk recovery tools (and even then, recovery isn't guaranteed).
Understand this command deeply before you use it in anger.
rm is Permanent
Linux has no built-in undo for rm. Deleted files do not go to a Trash folder — they are immediately unlinked from the filesystem. Recovery requires forensic tools and is not guaranteed, especially on SSDs with TRIM enabled.
Options
rm Options
| Option | Long Form | Description |
|---|---|---|
-r, -R | --recursive | Remove directories and their contents recursively |
-f | --force | Ignore non-existent files, never prompt |
-i | --interactive | Prompt before every removal |
-I | Prompt once if removing more than 3 files | |
-d | --dir | Remove empty directories |
-v | --verbose | Show each file as it's removed |
Danger Levels
Danger Scale
| Command | Risk | What it does |
|---|---|---|
rm file.txt | 🟢 Low | Remove a single known file |
rm *.log | 🟡 Medium | Remove all matching — verify with ls *.log first |
rm -r folder/ | 🟡 Medium | Remove directory tree |
rm -rf folder/ | 🔴 High | Force-remove entire tree, no prompts |
sudo rm -rf / | ☠️ CATASTROPHIC | NEVER DO THIS — destroys the entire system |
Examples
# ─── Remove files ────────────────────────────────────────────
rm file.txt # Delete single file
rm file1.txt file2.txt # Delete multiple files
rm *.log # Delete all .log files (CAREFUL!)
rm -v file.txt # Verbose: shows "removed 'file.txt'"
# ─── Remove directories ──────────────────────────────────────
rm -r folder/ # Remove directory and all contents
rm -rf folder/ # Force-remove (no prompts)
rm -d empty_folder/ # Remove ONLY if empty (safer)
rmdir empty_folder/ # Alternative for empty directories
# ─── Safe removal ────────────────────────────────────────────
rm -i file.txt # Prompt: "remove 'file.txt'? y"
rm -I *.log # Prompt once for 3+ files
rm -ri folder/ # Interactive recursive removal
# ─── Verbose removal ─────────────────────────────────────────
rm -rv old_project/ # See every file as it's removedSafety Practices
Always preview what you're about to delete before running rm with wildcards or -rf:
# ALWAYS preview wildcards first:
ls *.tmp # See what matches
rm *.tmp # Then remove
# Use echo for dry-run
echo rm -rf old_logs/ # Shows what WOULD run (doesn't delete)
# Add rm -i to .bashrc for interactive by default
echo "alias rm='rm -i'" >> ~/.bashrc
# Use trash-cli (install) instead of rm for recoverable deletes
sudo apt install trash-cli
trash file.txt # Moves to trash instead of permanent delete
trash-restore # Recover itThe -rf Pattern
rm -rf is the Linux way to clean up build artifacts, empty directories, and leftover files in scripts. It's fine and commonly used in controlled situations: rm -rf dist/ .next/ node_modules/. The danger is only when the path is wrong or comes from an untrusted variable. Always double-check your path before running rm -rf.
Before running `rm *.txt` on a directory with important files, what should you always do first?
Safe deletion practice:
- Create a test directory:
mkdir -p test_delete/logs - Create some files:
touch test_delete/{a,b,c}.txt test_delete/logs/{jan,feb}.log - Preview before deleting:
ls test_delete/*.txt - Delete only the .txt files:
rm test_delete/*.txt - Clean up the entire directory with one command — but use verbose so you see each deletion