Trash CLI Cheatsheet
Install
On Ubuntu 22.04, it was as easy as running:
sudo apt update && sudo apt install trash-cli
Cheats
List Trashed Files
trash-list
Move Files To Trash
Move Specific File To Trash
trash-put file1
Use With Find To Trash Specific Files
You can combine the trash-put command with find to trash specific files that you find. For example, the command below will trash files from the current directory that are older then 30 days
find . -maxdepth 1 -type f -mtime +30 | xargs --no-run-if-empty trash-put
Restore Trashed Files
If you want to restore a file from trash, run:
trash-restore
This will give you an indexed list of files. Press the number corresponding to the file you wish to restore and it will restore it to its original location.
Empty Trash
Remove Files Trashed More Than X Days
trash-empty $NUM_DAYS
Remove All Trashed Files
trash-empty
References
- Tecmint - Trash-cli – A Trashcan Tool to Manage ‘Trash’ from Linux Command Line
- Dev.to - Command Line Recycle-Bin For Linux System
Last updated: 22nd March 2024
First published: 22nd October 2023
First published: 22nd October 2023