This is the story of a guy who usually writes birthday posts on this birthday. This year calls for something completely different. Why? He feels that the posts could be perceived as boring and he agrees completely.

Usually, I’d write a post related to adding one year onto my age and stuff like that. Twenty-five. Well, now I don’t have to pay the underage fee to rent a car anymore! And my insurance should go down right? RIGHT?

Anyway, I’m sure those posts were boring to everybody else but me, so here’s something completely different:


extract () {
    if [ -f $1 ] ; then
        case $1 in
            *.tar.bz2)  tar xjf $1      ;;
            *.tar.gz)   tar xzf $1      ;;
            *.bz2)      bunzip2 $1      ;;
            *.rar)      rar x $1        ;;
            *.gz)       gunzip $1       ;;
            *.tar)      tar xf $1       ;;
            *.tbz2)     tar xjf $1      ;;
            *.tgz)      tar xzf $1      ;;
            *.zip)      unzip $1        ;;
            *.Z)        uncompress $1   ;;
            *)          echo "'$1' cannot be extracted via extract()" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}

Extract Anything (Bash)

This should go in your .bash_profilenow.

Did you do it yet? If you do have it, then isn’t it awesome? If not, then it’ll save you the hassle of trying to remember how to extract .tar, .tar.gz, bz2-whatever and .zip files on the command line! Sure, you might be a master with the tar zxvf stuff, but this is a must for those absent minded folk such as myself. :P

Well, with that I shall go celebrate being 25… and pondering how to get this geeky CLI feeling out of my system.

distort the message.

  1. #001Evan Walsh

    Congratulations on surviving another complete Earth rotation! Thanks for the gift of CLI knowledge!

    Now, go have some fun.

  2. #002Rob Schultz

    Happy Birthday. There’s something liberating about being able to rent a car and not having to pay the “I’m a punk kid” driver mark-up or premium insurance rates because most kids under 25 floor their Chevy Cobalts from stoplight to stoplight. Ah the perks of avoiding natural selection and surviving for a quarter of a century.

    Have a blow out bash.

  3. #003David Martin

    Awesome tip, happy birthday. I just realized that this is the only site I refuse to read in my RSS reader. It’s much better in person.

  4. #004Dimitry

    Wohoo, awesome little function man. Definitely gonna add that in!

    . ~/.bash_profile” to reload without restarting shell session.

    @Rob: I’m that “little punk kid” you’re talking about! Dreading turning 23…

  5. #005regi e.

    Damn apple heads!!! :p…. Happy B-Day “B”, now go get drunk and do something stupid. Its the only day of the year that you can get away with it.

  6. #006Matias

    Happy birthday man, and thanks for the LCLI gift. You have no idea how many times I’ve spent a good 10 minutes looking at tar —help to figure out how to compress a simple file, hehe ^_^

    Hope you have a good ‘un

  7. #007karla

    thanks for the tip :) belated happy birthday :D

  8. #008AJ

    Happy Birthday, Bryan. And thanks for the bash tip.

  9. #009Stefan

    Happy birthday! Thanks for this cool script.

  10. #010Bryan Veloso

    Thanks you guys! The clock has struck midnight and reality finally sets in. ;) Glad you all like the script. I’ll definitely do more of these if I run into any more!

  11. #011scott borowy

    Your car insurance doesn’t go down that much…at least in New England. Maybe in one month when I hit the big 2-6.

  12. #012Oliver

    Happy b’day — and what a useful script you have sir! Even if I am a day late…

  13. #013Paul Stamatiou

    @dimitry - if you’re asking what I think you’re asking.. about getting bash_profile to be read without restarting a session etc, you can use source to get OS X/*nix to reread the file.

    source ~/.bash_profile

  14. #014balls

    I have tiny balls…

  15. #015Rob Kerfia

    Just a really short addition I made for Mac OS X:

    *.dmg) hdiutil attach $1 ;; “”) echo -e Usage: extract ;;





Standard rules apply. Don't be stupid. Don't be an ass. Be critical but respectful. Don't step on the grass. Don't feed the animals. Use Markdown for HTML. Jumping off cliffs higher than 10-feet runs you the risk of serious injury. Don't hurt the badgers. I reserve the right to moderate.

Follow the rules, or I eat you.