Skip to content

Instantly share code, notes, and snippets.

@kevinkirkup
Created November 30, 2009 01:23
Show Gist options
  • Save kevinkirkup/245183 to your computer and use it in GitHub Desktop.
Save kevinkirkup/245183 to your computer and use it in GitHub Desktop.
Bash function to extract and type of archive
############################################################
# Function to extract archives
function extract() {
case $1 in
*.tar.bz2) tar xjvf "$1" ;;
*.tar.gz) tar xvzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xvf "$1" ;;
*.tbz2) tar xjvf "$1" ;;
*.tgz) tar xzvf "$1" ;;
*.zip) unzip "$1" ;;
*.7z) 7z x "$1" ;;
*.rar) unrar e "$1" ;;
*.jar) unzip "$1" ;;
*.apk) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*) echo "'$1' unknown compression type" ;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment