rm – remove files and directories

rm removes (deletes) files and directories. This is permanent — there’s no trash or undo.
Synopsis
rm [OPTIONS] FILE...
Common Options
| Option | Description |
|---|---|
-r, -R | Recursive (remove directories and contents) |
-f | Force, ignore nonexistent files, never prompt |
-i | Prompt before every removal |
-I | Prompt once before removing many files |
-v | Verbose, show files being removed |
-d | Remove empty directories |
Examples
Remove a file
$ rm file.txt
Remove multiple files
$ rm file1.txt file2.txt file3.txt
$ rm *.log
Remove with confirmation
$ rm -i important.txt
rm: remove regular file 'important.txt'? y
Remove directory and contents
$ rm -r old_project/
Force remove (no prompts)
$ rm -rf temp_folder/
Verbose output
$ rm -rv build/
removed 'build/cache/file1.tmp'
removed 'build/cache/file2.tmp'
removed directory 'build/cache'
removed 'build/output.log'
removed directory 'build'
Remove files starting with dash
$ rm -- -badfilename
# Or
$ rm ./-badfilename
⚠️ Dangerous Commands
Be extremely careful with these:
# DANGEROUS - deletes everything in current dir
$ rm -rf *
# CATASTROPHIC - deletes entire system (don't run!)
$ rm -rf /
Most modern systems protect against rm -rf / but always double-check your path before running rm -rf.
Safer Alternatives
Use trash instead of rm
# macOS
$ brew install trash
$ trash file.txt # Goes to Trash, recoverable
# Linux
$ sudo apt install trash-cli
$ trash-put file.txt
Interactive alias
# Add to ~/.bashrc
alias rm='rm -i'
Safe-rm package
# Prevents accidental deletion of critical paths
$ sudo apt install safe-rm
Tips
- No undo: rm is permanent — consider using
trashcommand - Test with ls first:
ls *.logbeforerm *.log - Use -i for safety: Especially when learning
- Avoid rm -rf wildcards:
rm -rf ./temp/*notrm -rf / temp/*(space = disaster) - Use find for selective deletion:
find . -name "*.tmp" -delete
See Also
Related Commands
- rmdir — Remove empty directories only
- mv — Move files (safer than delete)
- find — Find and delete files selectively






