Skip to content

Instantly share code, notes, and snippets.

@pfactum

pfactum/extract Secret

Created December 28, 2013 10:39
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 pfactum/5cf8e29838887764b1e5 to your computer and use it in GitHub Desktop.
Save pfactum/5cf8e29838887764b1e5 to your computer and use it in GitHub Desktop.
#!/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