Created
June 3, 2012 02:36
-
-
Save Gen2ly/2861045 to your computer and use it in GitHub Desktop.
Extract common file formats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Extract common file formats | |
# Display usage if no parameters given | |
if [[ -z "$@" ]]; then | |
echo " ${0##*/} <archive> - extract common file formats)" | |
exit | |
fi | |
# Required program(s) | |
req_progs=(7z unrar unzip) | |
for p in ${req_progs[@]}; do | |
hash "$p" 2>&- || \ | |
{ echo >&2 " Required program \"$p\" not installed."; exit 1; } | |
done | |
# Test if file exists | |
if [ ! -f "$@" ]; then | |
echo "File "$@" doesn't exist" | |
exit | |
fi | |
# Extract file by using extension as reference | |
case "$@" in | |
*.7z ) 7z x "$@" ;; | |
*.tar.bz2 ) tar xvjf "$@" ;; | |
*.bz2 ) bunzip2 "$@" ;; | |
*.deb ) ar vx "$@" ;; | |
*.tar.gz ) tar xvf "$@" ;; | |
*.gz ) gunzip "$@" ;; | |
*.tar ) tar xvf "$@" ;; | |
*.tbz2 ) tar xvjf "$@" ;; | |
*.tar.xz ) tar xvf "$@" ;; | |
*.tgz ) tar xvzf "$@" ;; | |
*.rar ) unrar x "$@" ;; | |
#*.rar ) 7z x "$@" ;; | |
*.zip ) unzip "$@" ;; | |
*.Z ) uncompress "$@" ;; | |
* ) echo " Unsupported file format" ;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment