Emulating the Recycling Bin in bash

I just ran into a problem where I accidentally erased a file that was very important and could not recover from it (it was a monstrous statistical model that takes about 5 hours to re-train…). I decided I had enough of this and needed a way to be able to recover from those silly mistakes (apparently not making them in the first place just wasn’t an option…) I wondered if anybody ever run into this problem, and what was their personal solution? Here is what I found and tested today (it works pretty well).

I know that there are processes that backs up your whole $HOME on a regular schedule, I forget the name of this process, but that’s not exactly what I need. I always liked the idea of a “recycling bin” from the GUI Operating Systems like Windows (or KDE) and decided that that’s exactly what I needed. I found the next best thing on the internet (See John’s Bash Tools for his original post).

I simply put this in my .bashrc and now can use “junk” instead of “rm”… It’s a pretty neat little trick actually. I then can use “empty_junk” every now and then to keep the size of my home reasonable. I could even add “empty_junk” in my .bashrc so that it gets emptied everytime I log on (I won’t because I often log onto twice at the same time and would create problems…).

##############################
# Emulating a reclycling bin #
##############################
# This function creates a directory called .junk
# and creates directories labeled by the date
# inside of this directory. Then, when a file is
# "junk"ed, it is actually just moved to this
# directory. The command line accepts as many
# files as you would care to junk, and can even
# work on entire directories. Be careful, since it
# is really just a wrapped "mv" command, you may
# overwrite your junked files if they both have
# the same name and end up in the root directory.
 
function junk () {
    TODAY=$(date +%d-%m-%y)
    if [ ! -e $HOME/.junk/$TODAY ]
    then
        mkdir -p $HOME/.junk/$TODAY
    fi
 
    for x in $@
    do
        mv $x $HOME/.junk/$TODAY
    done
}
 
# A very simple function to empty the trash.
# I set -Ri so that it recurses but prompts you.
 
function empty_junk () {
    rm -Ri $HOME/.junk/*
}

Apple introduces MacBook Air

During his Macworld Expo keynote address on Tuesday morning, Apple CEO Steve Jobs introduced the MacBook Air, a computer that the company billed as the world’s thinnest notebook — small enough to fit inside an interoffice mailing envelope. It’s priced starting at $1,799 and will be available within two weeks. (Read more)

Bah, not sure I want one. not a first generation one at least. I mean it’s not an iPod people! look at the size of it. the keyboard is probably going to melt within the first month or two that you have it… how can you keep the thing cool when you don’t have enough space to fit a optical drive in the thing? i have a hard time to keep my powerbook G4 cool as it is!

Plus it looks like it would break if I wasn’t too careful… i am not sure that the laptop providers need to keep the smaller the better attitude anymore… i think they hit the perfect thickness with the macbook pro. let’s add some SWEAT features to the computers and stop trying to fit it into my wallet… although that would be kind of cool.

my 2cents.

What’s going on with the weather?

So is it just that Toronto’s weather is a little warmer than Montreal’s or are we already feeling some of the effects of the so-called “global warming”? I don’t know what the answer is to that, but look at the forecast for the next two weeks! Ten days where the temperature is above average. Yikes!

I took this from the meteomedia‘s website, the number one source of weather in Canada! Ha ha. Crazy stuff!

The Story of Stuff

Someone showed me this awesome video, it’s actually part of a whole site, like David Suzuki’s Nature Challenge, on how to live green and how to make a real difference in this increasingly consumerist society.

Look at the teaser bellow, or simply go to http://www.storyofstuff.com/ to check the whole video. It’s about 20 minutes long but it’ll make you think a lot. Seriously, check it out.

© Copyright Bonuel Photography - Theme by Pexeto