Created
November 25, 2017 03:27
-
-
Save stefan2904/ef9e0d8071c7e51e01851a8de9dc74dc to your computer and use it in GitHub Desktop.
decompress, extract, unzip, unrar, untar, ...
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
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]" | |
return 1 | |
else | |
for n in $@ | |
do | |
if [ -f "$n" ] ; then | |
case "${n%,}" in | |
*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar) | |
tar xvf "$n" ;; | |
*.lzma) unlzma ./"$n" ;; | |
*.bz2) bunzip2 ./"$n" ;; | |
*.rar) unrar x -ad ./"$n" ;; | |
*.gz) gunzip ./"$n" ;; | |
*.zip) unzip ./"$n" ;; | |
*.z) uncompress ./"$n" ;; | |
*.7z|*.arj|*.cab|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.rpm|*.udf|*.wim|*.xar) | |
7z x ./"$n" ;; | |
*.xz) unxz ./"$n" ;; | |
*.exe) cabextract ./"$n" ;; | |
*) | |
echo "extract: '$n' - unknown archive method" | |
return 1 | |
;; | |
esac | |
else | |
echo "'$n' - file does not exist" | |
return 1 | |
fi | |
done | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
via https://www.digitalocean.com/community/tutorials/an-introduction-to-useful-bash-aliases-and-functions