Friday, October 21, 2011

Manage Trash From Command Line

Deleting files with the rm command is rather dangerous because of the difficulty of recovering a mistakingly deleted file.
That's where the Trash Can comes in handy, a temporary location that allows a permanent removal at a latter time.
I'm using Gnome and the location of the Trash is :
/home/$USER/.local/share/Trash
It contains two directories : files and info. The files folder contains the files deleted and the info directory consists of meta data for each deleted file.
Showing the Trash Can icon on the Desktop is done by going to :  
Menu > Applications > System Tools > Configuration Editor.
Just check the Key name /apps/nautilus/desktop/trash_icon_visible.  

Trash-cli manages the Trash in command line which is equivalent to Trash functionalities in Nautilus file browser.

There is no package in Squeeze, but you can install package trash-cli (0.1.10.28-2) from Sid without any problem.
I've tested it by issuing the command :
list-trash to list the files in the Trash Can :
It spits out errors :

Traceback (most recent call last): File "/usr/bin/list-trash", line 5, in for trashedfile in TrashDirectory.allTrashedFiles() : File "/usr/lib/pymodules/python2.6/libtrash.py", line 218, in allTrashedFiles for trashedfile in TrashDirectory.getHomeTrashDirectory().trashedFiles() : File "/usr/lib/pymodules/python2.6/libtrash.py", line 127, in trashedFiles ti.parse(open(infoFilename).read()) File "/usr/lib/pymodules/python2.6/libtrash.py", line 300, in parse raise ValueError() ValueError

Seems to be a bug :  http://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg882686.html
So you better go to the next page : http://code.google.com/p/trash-cli/ and download trash-cli-0.11.3-r315.tar.gz.
Extract it :  
tar xf trash-cli-0.11.3-r315.tar.gz
A directory  trash-cli-0.11.3-r315 is created with a INSTALL.txt with the instruction to install it :
Open up a terminal inside the directory and then as root :
python setup.py install 

running install
install_dir /usr/local/lib/python2.6/dist-packages/
Checking .pth file support in /usr/local/lib/python2.6/dist-packages/

....
Installing trash-list script to /usr/local/bin
Installing restore-trash script to /usr/local/bin
Installing trash-put script to /usr/local/bin
Installing volume-of script to /usr/local/bin
Installing trash-empty script to /usr/local/bin

....
Finished processing dependencies for trash-cli==0.11.3-r315

To remove file foo in the Trash Can, use  :
trash-put foo
To list all the contents of the Trash Can  :
trash-list
To restore a trashed file :
restore-trash
0 2011-10-20 23:47:05 /home/eric/Downloads/ruba 3tif.jpg
1 2011-10-20 23:47:25 /home/eric/Downloads/README.txt
2 2011-10-20 23:46:54 /home/eric/Downloads/NCw6L.jpg
What file to restore [0..2]:

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>

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.