Skip to content

Instantly share code, notes, and snippets.

@disconnect3d
Last active September 2, 2019 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save disconnect3d/0d644c239f04507741c0 to your computer and use it in GitHub Desktop.
Save disconnect3d/0d644c239f04507741c0 to your computer and use it in GitHub Desktop.
One extract to rule them all - simple bash function to extract any archive
function extract() {
if [ $# -ne 1 ]; then
echo "Usage: $FUNCNAME filename"
fi
filename=$1
if [ -f $filename ]; then
case $filename in
*.tar.xz) tar xvfJ $filename ;;
*.tar.gz) tar --gzip -xvf $filename ;;
*.tar.bz2) tar --bzip2 -xvf $filename ;;
*.tar) tar -xvf $filename ;;
*.tgz) tar --gzip -xvf $filename ;;
*.tbz2) tar --bzip2 -xvf $filename ;;
*.bz2) bunzip2 $filename ;;
*.7z) 7za x $filename ;;
*.Z) uncompress --keep $filename ;;
*.zip) unzip $filename -d ${filename%.*} ;;
*.rar) unrar x $filename ;;
*.jar) jar xf $filename ;;
*) echo "'$filename' not supported extension" ;;
esac
else
echo "'$filename' is not a file."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment