| name | trash-cli |
| version | 1.0.5 |
| description | Use trash-cli to safely delete files by moving them to the system trash instead of permanently removing them. This prevents accidental data loss and allows file recovery. Use instead of rm when you want recoverable deletion. |
| metadata | {"openclaw":{"emoji":"🗑️","requires":{"bins":"[Truncated]"},"install":["[Truncated]","[Truncated]"]}} |
trash-cli
A command line interface to the freedesktop.org trashcan. It trashes files recording the original path, deletion date, and permissions. It uses the same trashcan used by KDE, GNOME, and XFCE.
Installation
brew install trash-cli
pip install trash-cli
sudo apt install trash-cli
sudo pacman -S trash-cli
sudo dnf install trash-cli
Commands Overview
| Command | Description |
|---|
trash-put | Move files/directories to trash |
trash-list | List trashed files |
trash-restore | Restore trashed files |
trash-empty | Permanently delete trashed files |
trash-rm | Remove specific files from trash |
trash-put
Move files or directories to the trash can.
trash-put <file>
trash-put <dir>/
trash-put -f <file>
trash-put -v <file>
Options
-f, --force - Silently ignore nonexistent files
-v, --verbose - Explain what is being done
--trash-dir TRASHDIR - Use TRASHDIR as trash folder
Notes
- Unlike
rm, trash-put does not require -R for directories
- Files trashed from home partition go to
~/.local/share/Trash/
- Files from other partitions go to
$partition/.Trash/$uid or $partition/.Trash-$uid
trash-list
List all trashed files.
trash-list
trash-list | grep <pattern>
trash-list --all-users
Output Format
2008-06-01 10:30:48 /home/user/bar
2008-06-02 21:50:41 /home/user/baz
Format: deletion_date original_path
trash-restore
Restore trashed files to their original location.
trash-restore
trash-restore --overwrite
trash-restore --sort date
trash-restore --sort path
Interactive Mode
$ trash-restore
0 2007-08-30 12:36:00 /home/andrea/foo
1 2007-08-30 12:39:41 /home/andrea/bar
2 2007-08-30 12:39:41 /home/andrea/baz
What file to restore [0..2]: 0
- Enter the number to restore that file
- Use
0-2,3 to restore multiple files
- Use
--overwrite to replace existing files
trash-empty
Permanently remove files from trash.
trash-empty
trash-empty 7
trash-empty 1
Examples
trash-empty
trash-empty 7
trash-empty 1
trash-rm
Remove specific files from trash (by pattern).
trash-rm <pattern>
trash-rm '*.o'
trash-rm foo
trash-rm /full/path
Note: Use quotes to protect pattern from shell expansion.
trash-rm '*.log'
trash-rm *.log
Safety Tips
Replace rm with trash-put
Add to .bashrc or .zshrc:
alias rm='echo "Use trash-put instead!"; false'
alias rm='trash-put'
To bypass the alias when you really need rm:
\rm file.txt
Recovery Workflow
- Check what's in trash:
trash-list
- Find your file:
trash-list | grep <filename>
- Restore:
trash-restore
Trash Location
- Home partition:
~/.local/share/Trash/
- Other partitions:
$mount_point/.Trash/$uid or $mount_point/.Trash-$uid
Limitations
- Does not support BRTFS volumes
- Cannot trash files from read-only filesystems
FAQ
Creating a top-level .Trash directory
If you need to create a trash directory on a different partition:
sudo mkdir --parent /.Trash
sudo chmod a+rw /.Trash
sudo chmod +t /.Trash
Should I alias rm to trash-put?
The author advises against this. Although trash-put seems compatible with rm, it has different semantics that will cause problems. For example, while rm requires -R for deleting directories, trash-put does not.
Instead, use a warning alias:
alias rm='echo "This is not the command you are looking for."; false'
To bypass when you really need rm:
\rm file.txt
See Also