Trash-cli

Recycle Bin

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 uses 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 locations (recycle-bin). Trash-cli also remember 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 draw backs with this tool is 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).

Installing 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 6 can be download here

Working with trash-cli

Just setup 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