Last active
September 1, 2023 05:03
-
-
Save soraxas/ab594b0cf5c49b4e36c04249f0b7c2f7 to your computer and use it in GitHub Desktop.
script:Auto extraction tool based on the file extension
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 | |
| # from https://github.com/xvoland/Extract | |
| # function Extract for common file format | |
| SAVEIFS=$IFS | |
| IFS="$(printf '\n\t')" | |
| function extract { | |
| if [ -z "$1" ]; then | |
| # display usage if no parameters given | |
| echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>" | |
| echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]" | |
| else | |
| for n in "$@" | |
| do | |
| if [ -f "$n" ] ; then | |
| case "${n%,}" in | |
| *.cbt|*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar) | |
| tar xvf "$n" ;; | |
| *.lzma) unlzma ./"$n" ;; | |
| *.bz2) bunzip2 ./"$n" ;; | |
| *.cbr|*.rar) unrar x -ad ./"$n" ;; | |
| *.gz) gunzip ./"$n" ;; | |
| *.cbz|*.epub|*.zip) unzip ./"$n" ;; | |
| *.z) uncompress ./"$n" ;; | |
| *.7z|*.apk|*.arj|*.cab|*.cb7|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.pkg|*.rpm|*.udf|*.wim|*.xar) | |
| 7z x ./"$n" ;; | |
| *.xz) unxz ./"$n" ;; | |
| *.exe) cabextract ./"$n" ;; | |
| *.cpio) cpio -id < ./"$n" ;; | |
| *.cba|*.ace) unace x ./"$n" ;; | |
| *.zpaq) zpaq x ./"$n" ;; | |
| *.arc) arc e ./"$n" ;; | |
| *.cso) ciso 0 ./"$n" ./"$n.iso" && \ | |
| extract $n.iso && \rm -f $n ;; | |
| *) | |
| echo "extract: '$n' - unknown archive method" | |
| return 1 | |
| ;; | |
| esac | |
| else | |
| echo "'$n' - file does not exist" | |
| return 1 | |
| fi | |
| done | |
| fi | |
| } | |
| IFS=$SAVEIFS | |
| extract $@ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment