Trash-cli

 

Trash-cli is similar to the GUI based recycle bin but works under command line interfaces (cli). This tool is very much useful for the administrators who use only the command line mode. You can alias rm with trash-put so that the files which are deleted using rm command is not actually removed but stored under a separate location (recycle-bin). Trash-cli also remembers the date and time of file deletion which help us to recover the files/folder which is removed under specific time and also works for the external devices/drives like USB pen etc.

The only drawbacks with this tool are it is not easy to install it in CentOS / RHEL 5 and lesser version(it is possible if you upgrade the python & python-ctypes packages > 2.5.x version).

 

How to Install trash-cli

You can download the source code here but installing it via rpm is the easiest way the trash-cli rpm for centOS / RHEL.

Requirements:

  • Python 2.7 or Python 3
  • setuptools (use apt-get install python-setuptools on Debian)
# easy_install trash-cli

Install from sources

System-wide installation:

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

User-only installation:

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

 

Working with trash-cli

Just set up an alias of rm command with the trash-put so that the files you actually remove does not removed from the file system.

  • # mv /bin/rm /bin/rm.b
    # ln /usr/bin/trash-put /bin/rm

Or use can use the trash-put directly to remove the files/folders

  • # trash-put /home/gnu/file1.txt

To list all the contents of the trashcan

  • # trash-list
  • output2010-08-30 12:36:00 /home/gnu/file1.txt
    2010-08-30 12:39:41 /home/gnu/bar1.txt
    2010-08-30 12:39:41 /home/gnu/bar2.txt
    2010-08-30 12:39:41 /home/gnu/foo
     

Search for a specific file in the trashcan

  • # trash-list | grep file1.txt
    2010-08-30 12:36:00 /home/gnu/file1.txt

To restore a trashed file

  • # restore-trash
    2010-08-30 12:36:00 /home/gnu/file1.txt
    2010-08-30 12:39:41 /home/gnu/bar1.txt
    2010-08-30 12:39:41 /home/gnu/bar2.txt
    2010-08-30 12:39:41 /home/gnu/foo

To remove all trashed files

  • # trash-empty

To remove files that have been in the trash more than a given number of days

  • # trash-empty <days>  

Useful Links :

 

Trash-cli project home page