Saturday, October 10, 2009

how to safely delete things in Ubuntu/Linux

I accidentally performed a `rm -rf` on a very big and important directory. I was able to recover close to half of the files using extundelete, but it still left me with a sour taste in my mouth. Now that there is a solid freedesktop specification for how to Trash things, it seems high time to remedy this situation.

In my ~/.bashrc file:
if [ ! `which gvfs-trash 2>/dev/null` ]
alias dl='mv -t ~/.Trash/' # for older systems
alias dl='gvfs-trash'
So, now we can simply dl files and they go to a safe place. Still, I find myself using rm, so this little alias will help cure my addiction, by reminding me that I should be using dl instead of rm. I can still use the rm command by putting it in single quotes (that's how to get past any alias) as in: 'rm' -rf some_directory.
alias rm="echo \"use dl or 'rm'\""

No comments: