Unpack from typical archives in the shell

From ArchWiki

Jump to: navigation, search


This small guidance helps you to unpack different archives with only one command. For this you need unace, unzip and unrar.

In addition you must store only one file with the following content, for example with the name "unpack", in the directory "/usr/bin/" and make it executable with:

chmod +x /usr/bin/unpack

Content:

#!/bin/sh
while [ x"$1" != x ]; do
 case "$1" in
 *.tar.gz | *.tgz )
 tar -xzf "$1"
 shift
 ;;
 *.tar.bz2 | *.tbz )
 tar -xjf "$1"
 shift
 ;;
 *.zip)
 unzip "$1"
 shift
 ;;
 *.jar)
 unzip "$1"
 shift
 ;;
 *.war)
 unzip "$1"
 shift
 ;;
 *.ace)
 unace e "$1"
 shift
 ;;
 *.rar)
 unrar e "$1"
 shift
 ;;
 *.tar)
 tar -xf "$1"
 shift
 ;;
 *.gz)
 gunzip "$1"
 shift
 ;;
 *.bz2)
 bunzip2 "$1"
 shift
 ;;
 *)
 echo "file format not supported"
 shift
 ;;
 esac
done

That's it.

Personal tools