Programster's Blog

Tutorials focusing on Linux, programming, and open-source

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

Last updated: 22nd March 2024
First published: 22nd October 2023

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch