Trash-cli – A Trashcan Tool to Manage ‘Trash’ from Linux Command Line

[‘

n

Trash-cli is a command line interface that trashes files and records the original absolute path, deletion date, and associated permissions. It uses the same trashcan used by popular Linux desktop environments such as KDE, GNOME, and XFCE which can be invoked from the command line (and via scripts).

n

Trash-cli provides these commands:

n

$ trash-put           #trash files and directories.rn$ trash-empty         #empty the trashcan(s).rn$ trash-list          #list trashed files.rn$ trash-restore       #restore a trashed file.rn$ trash-rm            #remove individual files from the trashcan.rn

n

In this article, we will show you how to install and use trash-cli to find the original path, deletion date, and permissions of deleted files in Linux.

n

How to Install Trash-cli in Linux

n

The straightforward way of installing trash-cli is by using easy_install tool as follows:

n

$ sudo apt-get install python-setuptoolstt#Debian/Ubuntu systemsrn$ sudo yum install python-setuptoolsttt#RHEL/CentOS systemsrn$ sudo easy_install trash-clitrn

n

Else, install Trash-cli from source as shown.

n

$ git clone https://github.com/andreafrancia/trash-cli.gitrn$ cd trash-clirn$ sudo python setup.py installrn

n

How to Use Trash-cli in Linux

n

To trash a specific file, run.

n

$ trash-put file1rn

n

List all trashed files.

n

$ trash-listrnrn2017-05-05 10:30:48 /home/tecmint/file1rn2017-05-10 13:40:41 /home/tecmint/file2rn2017-05-12 22:30:49 /home/tecmint/file3rn2017-05-12 22:50:48 /home/tecmint/testrn

n

Search for a file in the trashcan.

n

$ trash-list | grep filernrn2017-05-05 10:30:48 /home/tecmint/file1rn2017-05-10 13:40:41 /home/tecmint/file2rn2017-05-12 22:30:49 /home/tecmint/file3rn

n

Restore a trashed file.

n

$ trash-restorernrn0 2017-05-05 10:30:48 /home/tecmint/file1rn1 2017-05-10 13:40:41 /home/tecmint/file2rn2 2017-05-12 22:30:49 /home/tecmint/file3rn3 2017-05-12 22:50:48 /home/tecmint/testrn

n

Remove all files from the trashcan.

n

$ trash-emptyrn

n

Remove only the files that have been deleted more than <days> ago:

n

$ trash-empty <days>rn

n

Here is a demonstration of this command:

n

$ daternMon May 15 20:26:52 EAT 2017rn$ trash-listrn2017-05-12 13:51:12 /home/tecmint/new.txtrn2017-05-11 10:41:30 /home/tecmint/old.txtrn2017-04-05 20:43:54 /home/tecmint/oldest.txtrn$ trash-empty  7rn$ trash-listrn2017-05-12 13:51:12 /home/tecmint/new.txtrn2017-05-11 10:41:30 /home/tecmint/old.txtrn$ trash-empty 1rn$ trash-listrn2017-05-12 13:51:12 /home/tecmint/new.txtrn

n

Remove only files matching a pattern.

n

Do not forget to use quotes in order to protect the pattern from shell expansion:

n

$ trash-rm  \*.txtrn

n

For more information, check out Trash-cli Github repository: https://github.com/andreafrancia/trash-cli

n

That’s all! Do you know of any similar CLI tools for Linux? Share some info about them with us via the comment form below.

n

‘]