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).

 

Trash-cli provides these commands:

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

 

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.

 

How to Install Trash-cli in Linux

 

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

$ sudo apt-get install python-setuptools		#Debian/Ubuntu systems
$ sudo yum install python-setuptools			#RHEL/CentOS systems
$ sudo easy_install trash-cli

 

Else, install Trash-cli from source as shown.

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

 

How to Use Trash-cli in Linux

 

To trash a specific file, run.

$ trash-put file1

 

List all trashed files.

$ trash-list

2019-05-05 10:30:48 /home/rootadminz/file1
2019-05-10 13:40:41 /home/rootadminz/file2
2019-05-12 22:30:49 /home/rootadminz/file3
2019-05-12 22:50:48 /home/rootadminz/test

 

 Search for a file in the trashcan.

$ trash-list | grep file

2019-05-05 10:30:48 /home/rootadminz/file1
2019-05-10 13:40:41 /home/rootadminz/file2
2019-05-12 22:30:49 /home/rootadminz/file3

 

Restore a trashed file.

$ trash-restore

0 2019-05-05 10:30:48 /home/rootadminz/file1
1 2019-05-10 13:40:41 /home/rootadminz/file2
2 2019-05-12 22:30:49 /home/rootadminz/file3
3 2019-05-12 22:50:48 /home/rootadminz/test

 

Remove all files from the trashcan.

$ trash-empty

 

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

$ trash-empty <days>

 

Here is a demonstration of this command:

$ date
Mon May 15 20:26:52 EAT 2019
$ trash-list
2019-05-12 13:51:12 /home/rootadminz/new.txt
2019-05-11 10:41:30 /home/rootadminz/old.txt
2019-04-05 20:43:54 /home/rootadminz/oldest.txt
$ trash-empty  7
$ trash-list
2019-05-12 13:51:12 /home/rootadminz/new.txt
2019-05-11 10:41:30 /home/rootadminz/old.txt
$ trash-empty 1
$ trash-list
2019-05-12 13:51:12 /home/rootadminz/new.txt

 

Remove only files matching a pattern.

 

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

$ trash-rm  \*.txt

 

Was this answer helpful? 0 Users Found This Useful (0 Votes)