I should’ve probably entitled this post “Learn from your mistakes”. Yesterday I was getting rid of the Windows partition in favor of a VMWare installation of Windows XP on my Ubuntu Hardy Heron (8.04) so I decided it was time to reclaim the space used by Windows and use it for my home partition. No biggie, I did everything right, and fast. Wait, so fast that I didn’t notice a big boo-boo:
$ rm -fR /var/backups/home/mariano; rm -fR /home/mariano.old; rm -fR /home/mariano
“You did what??” You ask.. Yup, that’s right, I wiped not only my Home directory, but every single backup copy I had of it. Granted, I didn’t have *much* on my home folder (except my evolution mail folders and some other documents), but I still wanted to shoot my hands for insisting in adding -fR to my rm commands (-fR means: delete recursively, and no, do not ask me for confirmation.)
So after trying without any luck to recover the deleted inodes, I’ve successfully re-setup my home folder starting fresh, which wasn’t so bad. In order not to mess up again, I’ve decided to add this little alias to my ~/.bashrc file:
# alias to make del send files to trash alias del='mv -t ~/.local/share/Trash/files --backup=t'
So from now on, I just need to remember to use “del” instead of “rm”, like so:
$ del example.txt
The above command would send example.txt to the trash, instead of wiping it out from the file system. You can later on decide to Empty the trash in your Desktop, or undelete your files. The del alias also works for folders.
Dennis Hennen [Visitor] wrote:
You can alias rm to something instead of using del. Since you are using Debian (Ubuntu) you could create a shell script to do this and use a diversion to direct /bin/rm to your shell script.
But most importantly, back up daily.
Link
mariano.iglesias [Member] wrote:
@Dennis: You shouldn’t do that. It is not what is expected of POSIX and you’d be altering what is expected from the rm command used by other scripts / tools.
Link
Bakyt Niyazov [Visitor] wrote:
Thank you! One interesting thing.
“del”eted items aren’t visible in the folder
If I use console I see the files. But not in D3lphin. very interesting. (tried to chmod 777, just for fun – not visible)
Thanks again!
Link
C. James Callaway [Visitor] wrote:
Takes the trash out to the curb. Files in your trashcan older than 14 days are removed. From a crontab, maybe?
#!/bin/bash -norc
# ~/bin/curb_trash
# deletes any trash files over $KEEPDAYS
TRASHDIR=~/.local/share/Trash/files
KEEPDAYS=14
########################################################################
# Cleanup old files
find $TRASHDIR \! -mtime -${KEEPDAYS} -exec rm {} \;
Link
Andrea Francia [Visitor] wrote:
You can also use the trash-cli software which provide a command line interface to trashcan. See http://code.google.com/p/trash-cli/
Link
Simple backup script for Ubuntu | Coding My Thoughts wrote:
[...] to prevent myself from another home fiasco, I’ve decided to build a simple script to backup some of my directories. There are a lot of [...]
Link
Deleting Command Line rm Moves File to Trash Instead | 3StrandsOfHair wrote:
[...] to prevent further mistake, I want to hedge myself. So I’m trying this technique suggested here to create an alias to rm which moves the files to trash instead. Note that I am executing Unix like [...]
Link