Created
January 30, 2017 12:23
-
-
Save pmav99/812ea078cbfc64300a2a4b1991393547 to your computer and use it in GitHub Desktop.
Linux extract snippet
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 | |
| # an extract command | |
| x() { | |
| local c e i | |
| (($#)) || return | |
| for i; do | |
| c='' | |
| e=1 | |
| if [[ ! -r $i ]]; then | |
| echo "$0: file is unreadable: \`$i'" >&2 | |
| continue | |
| fi | |
| case $i in | |
| *.tar) c=(bsdtar xvf);; | |
| *.tar.bz) c=(bsdtar xvf);; | |
| *.t@(gz|lz|xz|b@(2|z?(2))|a@(z|r?(.@(Z|bz?(2)|gz|lzma|xz))))) | |
| c=(bsdtar xvf);; | |
| *.7z) c=(7z x);; | |
| *.Z) c=(uncompress);; | |
| *.bz2) c=(bunzip2);; | |
| *.exe) c=(cabextract);; | |
| *.gz) c=(gunzip);; | |
| *.rar) c=(unrar x);; | |
| *.xz) c=(unxz);; | |
| *.zip) c=(unzip);; | |
| *) echo "$0: unrecognized file extension: \`$i'" >&2 | |
| continue;; | |
| esac | |
| command "${c[@]}" "$i" | |
| ((e = e || $?)) | |
| done | |
| return "$e" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment