rm
Overview
rm removes directory entries (unlinks files). By default it does not remove directories unless -r/-R is given. There is no undelete in coreutils — recovery requires backups, snapshots, or filesystem forensics.
Treat rm -rf as a loaded tool: verify the path, prefer dry-runs, and avoid root experiments on broad globs.
Syntax
rm [options] file...Common Options
| Option | Description |
|---|---|
-r, -R, --recursive |
Remove directories and their contents |
-f, --force |
Ignore missing files; never prompt |
-i |
Prompt before every removal |
-I |
Prompt once before removing many / recursive |
-v, --verbose |
Print each path as it is removed |
-d |
Remove empty directories (like rmdir) |
--one-file-system |
Do not recurse into different mount points |
--preserve-root |
Refuse to recursively remove / (default on GNU) |
--no-preserve-root |
Dangerous override — do not use casually |
--interactive=WHEN |
never, once, always |
Safety
Never experiment with rm -rf /, rm -rf /*, or unquoted root globs as root.
Prefer:
- Dry-run with
find … -printbefore-delete - Move to a quarantine directory first
trash-cli/ desktop trash when available- Snapshots (btrfs/zfs/LVM) for real recovery options
Do not rely on alias rm='rm -i' alone — scripts and other shells bypass aliases.
Examples with Explanations
Files
rm file.txt
rm -v file1 file2
rm -f stale.lock # no error if missingInteractive
rm -i *.log
rm -I -r build/ # single confirmation for recursiveDirectory trees
rm -r build/
rm -rf build/ # no prompts; double-check path firstEmpty directory only
rm -d empty_dir # fails if not empty
rmdir empty_dir # clearer intentDry-run then delete with find
find ./tmpdir -type f -name '*.tmp' -print
find ./tmpdir -type f -name '*.tmp' -delete
# or interactive:
find ./tmpdir -type f -name '*.tmp' -ok rm {} \;Stay on one filesystem
sudo rm -r --one-file-system /mnt/usb/dataAvoids descending into unexpected bind mounts.
Quarantine pattern
mkdir -p ~/QUARANTINE
mv suspect_dir ~/QUARANTINE/
# later, after review:
rm -rf ~/QUARANTINE/suspect_dirDeleted but space held open
rm huge.log
# space may not free until writers close the fd
sudo lsof +L1 | head
sudo lsof | grep '(deleted)'Notes / Pitfalls
- Globs expand in the shell before
rmruns —rm *is only as safe as your cwd. rm *skips dotfiles;rm -r dirremoves dotfiles insidedir.- Write permission on the parent directory is required to unlink a name (sticky bit on
/tmprestricts deleting others’ files). - On CoW/SSD,
shredis unreliable for sanitization; use disk encryption and secure erase procedures instead. - Root can remove almost anything — accidental paths under
/varor/homeare common outages.
2026-relevant notes
- Prefer immutable infrastructure and snapshots over hoping
rmis reversible. - Container layers: deleting in a running container does not shrink the image; rebuild layers properly.
- For selective cleanup,
find/fd+ review beats recursive force from the wrong cwd.
Additional Resources
man rm