Skip to content

Instantly share code, notes, and snippets.

@pfactum pfactum/extract Secret
Created Dec 28, 2013

Embed
What would you like to do?
#!/usr/bin/env bash
if [[ "-" == "-$1" ]]
then
echo Please specify file name
exit 1
fi
for i in "$@"
do
if [[ -f "$i" ]]
then
case "$i" in
*.tar.bz2 | *.tbz2 | *.tbz)
pbzip2 -v -d -c -- "$i" | tar xvf -
;;
*.tar.gz | *.tgz)
pigz -v -d -c -- "$i" | tar xvf -
;;
*.tar.xz | *.txz)
pixz -d "$i" /dev/stdout | tar xvf -
;;
*.tar.lrz | *.tlrz)
lrzip -vv -f -o - -d "$i" | tar xvf -
;;
*.tar.7z | *.t7z)
7z x -so "$i" | tar xvf -
;;
*.bz2)
pbzip2 -v -d -- "$i"
;;
*.rar)
unrar x "$i"
;;
*.gz)
pigz -v -d -- "$i"
;;
*.xz)
pixz -d "$i" "$(basename "$i" .xz)"
;;
*.lrz)
lrzip -vv -d "$i"
;;
*.tar)
tar xvf "$i"
;;
*.zip)
unzip "$i"
;;
*.Z)
uncompress "$i"
;;
*.7z)
7z x "$i"
;;
*)
echo "$i cannot be extracted via $(basename $0)"
;;
esac
else
echo "$i is not a valid file"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.