Thursday, March 4, 2010

My .bashrc File Part 3 - Making Life Easier

A very common thing to do in the command line is to extract compressed files. Now as many of you probably know there are a dozen different compression methods out there. Let's say I have a .bz2, .7z, .gz and a .rar file and I don't want to think about which app to use and what option I need to extract my file. I just want my file uncompressed. Let's make life a little easier and insert the following into your .bashrc file.

#------Extraction of compressed files--------------
# from ARCH Wiki

extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}

Now when you need to uncompress a file, simply type "extract filename" and slam-bam-thank-you-ma'am. No thinking or looking up the correct syntax, all you are left with is an uncompressed file and isn't that all we really wanted?

What fun things are you hiding in your .bashrc file that makes life easier? Please share.

3 comments:

Dave said...

That just went in my .bashrc file.
Tragedy though, I had to startX to comment this.

Dave said...

Correction, links2 -g worked just fine

abushcrafter said...

Even better is UNP:

http://www.murga-linux.com/puppy/viewtopic.php?p=432627#432627

unp installation and configuration in debian