Skip to content

Instantly share code, notes, and snippets.

@Wylbur
Created July 7, 2015 16:15
Show Gist options
  • Save Wylbur/5fadc924dbd1a4dc16ed to your computer and use it in GitHub Desktop.
Save Wylbur/5fadc924dbd1a4dc16ed to your computer and use it in GitHub Desktop.
Extract any file into a folder of that name
extract () {
if [ -f "$1" ] ; then
FDIR=$(basename "$1" | cut -d. -f1)
mkdir "$FDIR"
echo unrar x "$1" "FDIR"
case "$1" in
*.tar.bz2) tar xjf "$1" "$FDIR" ;;
*.tar.gz) tar xzf "$1" "$FDIR" ;;
*.bz2) bunzip2 "$1" "$FDIR" ;;
*.rar) unrar x "$1" "$FDIR"/ ;;
*.RAR) unrar x "$1" "$FDIR"/ ;;
*.gz) gunzip "$1" "$FDIR" ;;
*.tar) tar xf "$1" "$FDIR" ;;
*.tbz2) tar xjf "$1" "$FDIR" ;;
*.tgz) tar xzf "$1" "$FDIR" ;;
*.zip) unzip "$1" -d "$FDIR" ;;
*.ZIP) unzip "$1" -d "$FDIR" ;;
*.Z) uncompress "$1" "$FDIR" ;;
*.7z) 7z x "$1" "$FDIR" ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
rm "$1"
else
echo "'$1' is not a valid file"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment