After getting tired of trying to remember “tar xvzf”, I wrote a little script for extracting almost any file type via the linux command-line. You can copy and paste this script into a text editor like gedit and save it to “/usr/local/bin” for convenience. I called mine “untar” since it doesn’t seem to be taken. Remember to `chmod +x
#!/bin/sh
me=`basename $0`
if [ $# -eq 0 ]; then
echo "usage: $me <files...>"
fi
for file in $@; do
bn=`basename $file`
case $file in
*.tar)
tar xvf $file;;
*.tar.gz|*.tgz|*.tar.Z|*.tar.z)
tar xvzf $file;;
*.tar.bz2)
tar xvjf $file;;
*.zip)
unzip $file;;
*.rar)
unrar x $file;;
*)
echo "$me: $bn: unkown filetype";;
esac
done
me=`basename $0`
if [ $# -eq 0 ]; then
echo "usage: $me <files...>"
fi
for file in $@; do
bn=`basename $file`
case $file in
*.tar)
tar xvf $file;;
*.tar.gz|*.tgz|*.tar.Z|*.tar.z)
tar xvzf $file;;
*.tar.bz2)
tar xvjf $file;;
*.zip)
unzip $file;;
*.rar)
unrar x $file;;
*)
echo "$me: $bn: unkown filetype";;
esac
done
One thought on “Extract (almost) any archive type”
I have to do a “tar –help” each time I need to decompress something. This really is useful. Named mine extract. Didn’t seem to be taken on cygwin.
bucabay