Articles

[SCRIPT] Easy unpack compressed files


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

 

unpack.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/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