Thursday, April 23, 2009

RM replacement using TrashCan in Ubuntu

When using a GUI we have the luxury or a Trash Can when we delete the wrong thing by accident. With a CLI, there is no such luxury when using the rm command. So I made one. It works by adding the following lines of code to your ~/.bashrc file and then reload your Terminal session. It works by typing "del [filename]". This moves the file to the Trash Can for you to delete later at your convenience and it supports restoring the file back to its original location using the GUI "Restore" option.
I have tested this on Ubuntu 8.10 and 9.04 desktop editions.

function del {
mv $1 ~/.local/share/Trash/files
touch ~/.local/share/Trash/info/$1.trashinfo
echo "[Trash Info]" >> ~/.local/share/Trash/info/$1.trashinfo
echo "Path=$PWD/$1" >> ~/.local/share/Trash/info/$1.trashinfo
DATE=`date "+%Y-%m-%dT%T"`
echo "DeletionDate=$DATE" >> ~/.local/share/Trash/info/$1.trashinfo

1 comment:

  1. does not work with del file1 file2 file3. May be better to use trash-cli. Though it also has (or had) some problems with names with spaces.


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