Safe Delete in Linux
(Recycle Bin for the Terminal)
Last updated 2026-08-20 · 5 notes · 4 tags
Tags: trash safety linux wsl
Unlike Windows Explorer, Linux rm permanently deletes files. There is no built-in Recycle Bin for that command. This is the solution...
rm myfile.py
If the file was never committed to Git and not backed up, recovery is usually impossible.
Note: This guide works the same on WSL and native Linux.
Install trash-cli
sudo apt update
sudo apt install trash-cli
Basic usage
Instead of permanent delete:
trash-put path/to/file
List trash:
trash-list
Restore (interactive list):
trash-restore
Empty trash:
trash-empty
Only remove items older than 30 days:
trash-empty 30
Note:
trash-putmoves files to a Trash folder; it does not wipe the disk immediately.
Make rm safer with an alias
Edit your shell config:
nano ~/.bashrc
Add at the end:
alias rm='trash-put'
Save, exit, then reload:
source ~/.bashrc
Check:
alias rm
Expected: alias rm='trash-put'
Note: After this, typing
rm file.pysends the file to Trash instead of deleting it permanently.
Permanent delete when you really mean it
Bypass the alias:
\rm file.py
or:
command rm file.py
Note: Use permanent delete sparingly. Prefer Git history for important work you might need again.
Recommended workflow
- Day-to-day experiments: delete with
rm(aliased to trash) and restore if needed. - Anything that took real effort: commit to Git before you clean up. Trash protects accidents between commits; Git protects longer-term history.
Note: Trash is not a backup system. It lives on the same machine.
Summary
| Task | Command |
|---|---|
| Install | sudo apt install trash-cli |
| Delete to Trash | trash-put file.py or aliased rm file.py |
| List | trash-list |
| Restore | trash-restore |
| Empty | trash-empty |
| Permanent delete | \rm file.py |
| Check alias | alias rm |
This project captures ideas, decisions, and lessons I’ve learned while building with AI. It aims to help non-technical users understand and use these tools effectively. I also use AI at times to improve or refine the content.
Readers should use the commands and instructions here with care. The creator accepts no responsibility for system damage, data loss or other consequences resulting from their use.