You are not logged in.
I know that this is easily done using Fileroller or similar GUI applications.
But I like to do most of my file operations using Terminals, because it's faster and I always gets the appropriate outputs if something goes wrong.
This tip is from the Arch Wiki and is one of my favourites 
Open ~/.bashrc in your preferred editor and paste the following in the bottom of this file:
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
}For making this to take effect immediately type this command in your preferred terminal:
source .bashrcFind a compressed file ie. (foo.tar.gz) and type this:
extract foo.tar.gzVoila 
Last edited by Scrat (2009-01-13 11:01:27)
/Niels
Registered Linux user #133791 > Get counted at http://counter.li.org
-----------------------------------------------------------------------
So Many Things To Do, And No Time For Nuts !
Offline
Awesome tip, much thanks! We really do need a thank you button. 
.files
dnyy in IRC & Urban Terror
Offline
Awesome tip, much thanks! We really do need a thank you button.
I got to second that. Great tip.
-Bob-
Ubuntu User #24005, Linux User #480025
identi.ca friendfeed facebook
Offline
great script!
i can't remember everytime tar -xvfsjsxsdtxxx.... 
Offline
AWESOME! I can never remember all of those switches to extract things.
I guess I will never learn them now, and even be upset when I am on another system and type extract and it bonks at me!
Thanks for that addition.
Michael
The 1-Man IT Department | Ubuntu User #16666 | Linux User #451972
My Social Nets: Identi.ca | twitter | friendfeed
Crunchbangin' and Loving Every Minute of IT!
Offline
thank you scrat! 
Offline
how do i get fileroller?
Offline
It should already be included in #!. If you don't have it, you can install it by running "sudo apt-get install file-roller".
Note: ** Please read before posting **
BTW if you wish to contact me, send me an e-mail instead of a PM.
Offline
Thanks Scrat, this is a useful tip.
Last edited by karthik (2009-05-14 08:49:52)
Offline
An improvement, for when dealing with several archives:
extract () {
for archive in $*; do
if [ -f $archive ] ; then
case $archive in
*.tar.bz2) tar xvjf $archive ;;
*.tar.gz) tar xvzf $archive ;;
*.bz2) bunzip2 $archive ;;
*.rar) rar x $archive ;;
*.gz) gunzip $archive ;;
*.tar) tar xvf $archive ;;
*.tbz2) tar xvjf $archive ;;
*.tgz) tar xvzf $archive ;;
*.zip) unzip $archive ;;
*.Z) uncompress $archive ;;
*.7z) 7z x $archive ;;
*) echo "don't know how to extract '$archive'..." ;;
esac
else
echo "'$archive' is not a valid file!"
fi
done
}Can be used like so:
$ extract *.tar.gz *.zip
Last edited by karthik (2009-05-25 19:42:00)
Offline
Pressed imaginary thank you button:)
Linux user #366129
Offline
And the next level will be having the script identify the file by its mime-type 
It seems that every community is unique for some things. I read alot of links to #! when it comes to conky and Arch is a script factory par exellence 
I'm so meta, even this acronym
Offline
WOW! This is awesome.
#!Crunchbang - an inverted wall of learning, definitely no curve!
Offline
Very nice. This is enlightenment... it's almost as if I understand computers now.... Nope, not yet.
haha Very helpful.
Question to anyone who reads this... can this be applied system wide? I only have it in my homefolder where the script will work.
Thefefore I must:
cp /folder/file.gz /home/USER/ cd /home/USER/ extract file.gz I like using this for man files and the like... not all of them come pre-extracted.
Last edited by lightning_underscore (2012-02-05 22:13:48)
Offline
just put it in /usr/bin or somewhere in $PATH, then it'll work from wherever.
Punch all your friends.
Offline
Put the function definition in your $HOME/.bashrc (append it to the end of .bashrc)
Log out and log in again
You then will be able to use it everywhere.
bootinfoscript - emacs primer - I ♥ #!
Offline
Can I just offer a small variation to this great tip please. There is actually a 'built-in' command in Linux called 'extract'. At any point in time you may or may not have the util package installed that includes it; but, if it is installed it will conflict with the command from this tip. That can cause the system to give unexpected results.
I have been using this for years in all sorts of distros and I have found the easiest way to avoid the conflict arising is to change the name of this tip command to just "extr" rather than the full word extract. Here is the relevant section from my .bashrc file:
# universal tarball extractor
extr () {
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 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extr()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}Also, make sure you have all of the programs installed that actually do the extractions.
Works really well.
cheers,
Greywolf.
Last edited by greywolf (2012-02-06 11:32:18)
Life isn't about waiting for the storm to pass...
it's about learning to dance in the rain.
Offline
There's a package in the Debian repos, called unp. It's a wrapper around tar, unzip and gang. You just do unp archive.
Offline
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.