Removing Files (rm)
The rm command removes files and directories. It's powerful but dangerous - deleted files don't go to a trash bin.
Basic Usage
rm filename
Important Warning
rm is permanent! Unlike graphical file managers, rm doesn't use a trash bin. Deleted files are gone forever.
Always:
- Double-check before pressing Enter
- Use
-iwhen unsure - Avoid
rm -rf /at all costs
rm Options
| Option | Description |
|---|---|
-i | Interactive (prompt before each removal) |
-r | Recursive (remove directories) |
-f | Force (ignore nonexistent, no prompt) |
-v | Verbose (show files being removed) |
-d | Remove empty directories |
Removing Directories
Use -r for directories:
rm -r directory_name
The Dangerous -rf Flag
rm -rf removes everything without prompting:
rm -rf folder/ # Removes folder and all contents
Use with extreme caution! Many system disasters start with rm -rf.
Exercise: Remove a File
Remove a file you create:
Safe Removal Practices
Always Use Interactive Mode
rm -i important_file.txt
# rm: remove regular file 'important_file.txt'?
Check Before Removing
ls file_to_delete.txt # Verify it exists
rm file_to_delete.txt # Then remove
Use Verbose Mode
rm -v *.log
# removed 'app.log'
# removed 'error.log'
Removing Multiple Files
rm file1.txt file2.txt file3.txt
rm *.tmp # All .tmp files
rm -r old_backups/ # Directory and contents
What NOT to Do
# NEVER run these:
rm -rf / # Destroys system
rm -rf ~ # Destroys home directory
rm -rf * # Dangerous in wrong directory
Alternatives to rm
Move to Trash (safer)
# Create a trash function
mv file.txt ~/.trash/
Use trash-cli
trash-put file.txt # Moves to trash
trash-list # Lists trash
trash-restore # Restores files
Troubleshooting
| Error | Cause | Solution |
|---|---|---|
Is a directory | Using rm without -r | Use rm -r or rmdir |
Permission denied | No write access | Check permissions |
No such file | File doesn't exist | Check spelling |
Key Takeaways
rmpermanently removes files (no trash!)- Use
-rfor directories - Always double-check before using
-rf - Use
-ifor interactive confirmation - Consider safer alternatives for important files

