Safe Delete
(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 content repository is based on the hands-on experience of Naveen Bachwani. AI tools were also used in augmenting and refining it. The goal is to help non-technical users get familiar with these tools, so they may be able to use them effectively.
Readers are responsible for using any commands or instructions provided here with appropriate caution. The creator of this site accepts no responsibility for system damage, data loss, or other consequences resulting from their use.