📘 Overview
On Linux, the command-line tool trash-cli provides a safe alternative to rm, allowing you to move files to the Trash instead of permanently deleting them.
It fully complies with the FreeDesktop Trash Specification, which is used by desktop environments such as GNOME and KDE.
🧰 Installation
You can install trash-cli using your package manager or Python’s pip:
| |
🚫 Disable rm (for safety)
To avoid accidental permanent deletions, you can override the rm command and display a friendly warning instead.
Add this alias to your ~/.bashrc or ~/.zshrc:
| |
Then reload your shell:
| |
Now, if you accidentally type rm, you’ll get a helpful message instead of deleting files permanently.
🧩 How trash-cli Manages Trash Directories
1. Per-Partition Trash Design
Linux doesn’t use a single, global trash folder.
Instead, trash-cli follows the FreeDesktop specification, which defines a separate trash directory for each filesystem (partition).
This prevents large files from being copied across devices when deleted.
| Location Type | Trash Directory |
|---|---|
| Your Home Directory | ~/.local/share/Trash/ |
| Other Filesystems | /mountpoint/.Trash-$UID/ (e.g. /data0/.Trash-1000/) |
(where $UID is your numeric user ID.)
Each trash directory contains two subfolders:
files/ → stores deleted files
info/ → stores metadata (.trashinfo files)
Example:
~/.local/share/Trash/
├── files/
│ └── test.png
└── info/
└── test.png.trashinfo
Metadata example:
| |
2. How to Check Where Your Trash Is
Method 1: View home trash
| |
Method 2: Search all trash directories
| |
Method 3: List all trashed files
| |
Method 4: Check where a deleted file went
| |
3. Why It’s Per-Partition
Prevents cross-device copying when deleting large files
Keeps trash on the same filesystem for safety and performance
Supports multiple users with separate
.Trash-$UIDdirectories
⚙️ Optional: Use a Global Trash Folder
If you really prefer a single global trash instead of per-filesystem behavior, you can override it (though it’s not standard):
| |
🧹 Common Commands
| Command | Description |
|---|---|
trash-put / trash | Move file to trash |
trash-list | List trashed files |
trash-restore | Restore deleted file |
trash-empty | Empty all trash bins |
trash-rm pattern | Remove specific trashed files |
✅ Summary
| Concept | Explanation |
|---|---|
| System | Follows FreeDesktop Trash spec |
| Trash structure | Per-filesystem (.Trash-$UID) |
| Home trash location | ~/.local/share/Trash |
| Metadata folder | info/ stores .trashinfo files |
| Safe delete | Use trash-put instead of rm |
| Restore | Use trash-restore |
| Empty | Use trash-empty |