Search This Blog

Thursday, November 28, 2013

Force 'rm' to use Trash instead of removing files completely

This one's great.
Just realized that Linux system, by default, does not move data to Trash/Bin folders. It's the Desktop Environment that does so.
So when you 'rm -rf file', it does not send the files to Trash. If you have deleted some important files by mistake or you want to recover some files which had been accidentally removed using 'rm', you could be in trouble.

Here is what you can do to avoid such situations:
Replace 'rm' with a simple bash script which will move the deleted files to .Trash folder:

Note: Shamelessly copied as is from the forum link in the references below.

1. Backup original 'rm' command.

user@ubuntu:~$ sudo mv /usr/bin/rm /usr/bin/rm.bak


2. Edit /usr/bin/rm in your favorite editor and put this in:

#!/bin/bash

mkdir ~/.Trash &> /dev/null

while [ ! -z "$1" ]; do
    mv "$1" ~/.Trash/
    shift
done


..............Done!!!

Reference(s):
http://www.linuxforums.org/forum/newbie/69673-not-possible-recover-files-deleted-using-rm.html#post364949

No comments:

Post a Comment