As the antithesis of yesterdays pack command there is unpack.
Unpack
This script was originally written by brisbin33 in the Arch forums (beautiful work man) and is slightly-modified. It will unpack most compressed file formats. Syntax is:
unpack <archive.ext>

tar is able to detect what kind of compression is used, so “tar xvf $1″ is sufficient. So this should be enough:
case $1 in
…
*.tar|*.tar.gz|*.tar.bz2|*.tar.lzma|*.tar.xz|*.tgz|*.tbz2) tar xvf $1 ${2:+-C $2} ;;
…
Yeah, I know that tar does this now but decided to leave this in because sometimes I work in the BSD world and tar is a bit more legacy there. However that command is very, Nice! Didn’t know that tar could do lzma. Could you explain what the ${2:+-C $2} does?
Doesn’t BSD use the same GNU-packages as Linux? Then it should just work… give it a try and you know :)
For gzip and bzip2 at last it should, those are included for ages.
Support for lzma was added about a year ago, xz a few months ago.
${var:+something} means: if $var is set and not empty, then use “something”.
It’s the reverse of ${var:-something}, which means: if $var is empty or does not exist, then use “something”. Very handy.
If you leave out the colon, the empty-part doesn’t apply.
Example: ${var-text} means: if $var doesn’t exist, then use “text”. NOT if $var does exist, but is unset/null/blank.
So ${2:+-C $2} means: if you specified a directory ($2), then use “tar xvf -C $2″, otherwise use “tar xvf”. A little trick to modify parameter $2 :)
A few more of these: http://www.delorie.com/gnu/docs/bash/bashref_29.html
Yeah, BSD utils can be different. I usually use OpenBSD and tools there are not the same. I think it has to do with the BSD and GPL licenses, but I’ve tried NetBSD… Some options will be there, not others, and some even a re completely different.
Always good to get these bash tips. Nice.
[...] Source. Enjoy [...]
look at this version https://github.com/xvoland/Extract