rm removes (deletes) files and directories. Unlike Finder, deleted files don't go to Trash - they're gone immediately.
Basic Usage
rm filename
The file is deleted. No confirmation, no undo.
Delete Multiple Files
rm file1.txt file2.txt file3.txt
Or with wildcards:
rm *.tmp
rm *.log
Delete Directories (-r)
Directories require -r (recursive):
rm -r foldername
Deletes the folder and everything inside it.
Without -r:
rm: foldername: is a directory
The Dangerous Command
You've probably heard about this:
rm -rf /
Never run this. It deletes everything on your drive. The flags mean:
-r- recursive (delete directories)-f- force (don't ask, ignore errors)
Modern macOS has protections, but variations can still cause damage.
Safe Usage Practices
1. Use -i for confirmation:
rm -i file.txt
Asks before each deletion:
remove file.txt? y
2. Use wildcards carefully:
First check what matches:
ls *.log
Then delete:
rm *.log
3. Double-check before hitting Enter:
Read the command. Make sure the path is right.
Common Options
| Option | Effect |
|---|---|
-r |
Recursive (for directories) |
-i |
Interactive (confirm each file) |
-f |
Force (no confirmation, no errors) |
-v |
Verbose (show what's deleted) |
Interactive Mode (-i)
rm -ri folder/
Asks about each file:
examine files in directory folder/? y
remove folder/file1.txt? y
remove folder/file2.txt? n
Verbose Mode (-v)
rm -rv folder/
Shows what's being deleted:
folder/file1.txt
folder/file2.txt
folder/
Delete Empty Directory
For empty directories, you can use rmdir:
rmdir emptyfolder
Safer than rm -r because it only works on empty directories.
Move to Trash Instead
If you want files to go to Trash:
# Using built-in command (macOS Sonoma and later)
trash file.txt
# Or install trash-cli via Homebrew
brew install trash-cli
trash file.txt
Or create a safer alias:
# Add to ~/.zshrc
alias rm='rm -i'
Now rm always asks for confirmation.
Recovering Deleted Files
Short answer: You probably can't.
rm doesn't move files to Trash - it removes filesystem entries. Recovery tools might work if:
- The disk hasn't been written to since
- You have specialized recovery software
- You have backups (Time Machine, etc.)
Best practice: Use Trash or backup important files before deleting.
Practical Examples
Clean up old logs:
rm *.log
Delete a project folder:
rm -r old-project/
Delete everything in current folder:
rm -r *
Delete files older than 30 days:
find . -mtime +30 -delete
Wildcards
| Pattern | Matches |
|---|---|
* |
Everything |
*.txt |
All .txt files |
file* |
Files starting with "file" |
*.{jpg,png} |
All .jpg and .png files |
test?.txt |
test1.txt, test2.txt, etc. |
Common Errors
"Permission denied":
- File is protected or owned by another user
- Try
sudo rmif you're sure you should delete it
"No such file or directory":
- File doesn't exist or path is wrong
- Check with
lsfirst
"Directory not empty":
- Using
rmdiron a folder with files - Use
rm -rinstead
Quick Reference
| Command | Result |
|---|---|
rm file.txt |
Delete file |
rm -i file.txt |
Delete with confirmation |
rm -r folder/ |
Delete folder and contents |
rm *.log |
Delete all .log files |
rmdir folder/ |
Delete empty folder only |
Keep Learning
rm is powerful and permanent. The free course teaches safe file management practices.
Check it out at Mac Terminal for Humans.