Jun172008

Delete files from command line to Trash in Ubuntu 8.04

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.



Leave a Comment

7 Comments to "Delete files from command line to Trash in Ubuntu 8.04"

  1. Jun172008 at 10:13 pm

    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.

  2. Jun182008 at 10:16 am

    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.

  3. Jun282008 at 1:28 pm

    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!

  4. Aug062008 at 12:18 am

    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 {} \;

  5. Mar292009 at 12:54 am

    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/

  6. Dec312009 at 1:16 pm

    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 [...]

  7. Sep182012 at 12:06 pm

    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 [...]

 
Powered by Wordpress and MySQL. Clauz's design for by Cricava