Page 1 of 1

[SCRIPT] Unpack compressed files

Posted: 29 Dec 2010, 06:34
by brokenman
Do you keep forgetting the different switches for unpacking tarballs?

Paste this into a text file, save it as /usr/bin/unpack
Make it executable: chmod +x /usr/bin/unpack
Now to unpack most compressed files just use: unpack myfile.tar.bz2

Code: Select all

#!/bin/bash

INPUT=$1
FEXT=$(echo $1 | grep -o '\.[^.]*$')
case "$FEXT" in
".bz2")
tar -jxvf $INPUT;
;;
".gz")
tar -zxvf $INPUT
;;
".tar")
tar -xvf $INPUT;
;;
".zip")
unzip $INPUT;
esac