Source

bin / extract

#!/bin/bash
# Extract files.

if [ -f "$1" ]; then
    case "$1" in
        *.tar*|*.tgz|*.tbz2)    tar xf "$1"   ;;
        *.gz)       gunzip "$1"   ;;
        *.bz2)      bunzip2 "$1"  ;;
        *.zip)      unzip "$1"    ;;
        *.rar)      unrar x "$1"  ;;
        *.ace)      unace x "$1"  ;;
        *.Z)        uncompress "$1"   ;;
        *.7z)       7z x "$1" ;;
        *)          echo "'$1' cannot be extracted" ;;
    esac
else
    echo "'$1' is not a valid file"
fi