Skip to content

Instantly share code, notes, and snippets.

@aeakett
Created January 23, 2013 19:21
Show Gist options
  • Save aeakett/4611834 to your computer and use it in GitHub Desktop.
Save aeakett/4611834 to your computer and use it in GitHub Desktop.
shell function to extract most archives with one command (also corrals the contents of files that are known to be tarbombs)
# extract most archives with one command
# (also corrals the contents of files that are known to be tarbombs)
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.tar) tar xf $1 ;;
*.tgz) tar xzf $1 ;;
*.tbz2) tar xjf $1 ;;
*.gz) gunzip $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*.cbr) mkdir $1-extracted; cd $1-extracted; cp ../$1 ./; unrar e $1; rm $1; cd .. ;;
*.cbz) mkdir $1-extracted; cd $1-extracted; cp ../$1 ./; unzip $1; rm $1; cd .. ;;
*.cb7) mkdir $1-extracted; cd $1-extracted; cp ../$1 ./; 7z x $1; rm $1; cd .. ;;
*.jar) mkdir $1-extracted; cd $1-extracted; cp ../$1 ./; unzip $1; rm $1; cd .. ;;
*.epub) mkdir $1-extracted; cd $1-extracted; cp ../$1 ./; unzip $1; rm $1; cd .. ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment