rm Cheatsheet
Basic Syntax
Core command forms for file and directory removal.
| Command | Description |
|---|---|
rm [OPTIONS] FILE... |
Remove one or more files |
rm -r [OPTIONS] DIRECTORY... |
Remove directories recursively |
rm -- FILE |
Treat argument as filename even if it starts with - |
rm -i FILE |
Prompt before each removal |
Remove Files
Common file deletion commands.
| Command | Description |
|---|---|
rm file.txt |
Remove one file |
rm file1 file2 file3 |
Remove multiple files |
rm *.log |
Remove files matching pattern |
rm -- -strange-filename |
Remove file named with leading - |
rm -v file.txt |
Remove file with verbose output |
Remove Directories
Delete directories and their contents.
| Command | Description |
|---|---|
rm -r dir/ |
Remove directory recursively |
rm -rf dir/ |
Force recursive removal without prompts |
rm -r dir1 dir2 |
Remove multiple directories |
rm -r -- */ |
Remove all directories in current path |
Prompt and Safety Options
Control how aggressively rm deletes files.
| Command | Description |
|---|---|
rm -i file.txt |
Prompt before each file removal |
rm -I file1 file2 |
Prompt once before deleting many files |
rm --interactive=always file.txt |
Always prompt |
rm --interactive=once *.tmp |
Prompt once |
rm -f file.txt |
Ignore nonexistent files, never prompt |
Useful Patterns
Frequent real-world combinations.
| Command | Description |
|---|---|
find . -type f -name '*.tmp' -delete |
Remove matching temporary files |
find . -type d -empty -delete |
Remove empty directories |
rm -rf -- build/ dist/ |
Remove common build directories |
rm -f -- *.bak *.old |
Remove backup files quietly |
Troubleshooting
Quick checks for common removal errors.
| Issue | Check |
|---|---|
Permission denied |
Check ownership and permissions; use sudo only when needed |
Is a directory |
Add -r to remove directories |
No such file or directory |
Verify path and shell glob expansion |
| Cannot remove write-protected file | Use -i for prompts or -f to force |
File name starts with - |
Use rm -- filename |
Related Guides
Use these references for safer file management workflows.
| Guide | Description |
|---|---|
Rm Command in Linux
|
Full rm guide with examples |
How to Find Files in Linux Using the Command Line
|
Find and target files before deleting |
Chmod Command in Linux
|
Fix permission errors before removal |
Linux Commands Cheatsheet
|
General Linux command quick reference |
