Skip to content

Instantly share code, notes, and snippets.

@colehocking
Created August 16, 2021 17:09
Show Gist options
  • Save colehocking/e208e39ba1c4d474ad9a1545c260265d to your computer and use it in GitHub Desktop.
Save colehocking/e208e39ba1c4d474ad9a1545c260265d to your computer and use it in GitHub Desktop.
timesave extract process
#!/bin/bash
extract() {
if [[ -z "$1" ]]; then
echo "Usage: extract <file>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
exit 1
else
if [[ -f "$1" ]]; then
case $1 in
*.7z) 7z x $1;;
*.tar.bz2) tar xvjf $1;;
*.tar.gz) tar xvzf $1;;
*.bz2) bunzip2 $1;;
*.gz) gunzip $1;;
*.tar.xz) tar xvJf $1;;
*.tar) tar xvf $1;;
*.tbz2) tar xvjf $1;;
*.tgz) tar xvzf $1;;
*.Z) uncompress $1;;
*.xz) unxz $1;;
*.lzma) unlzma $1;;
*.rar) unrar x -ad $1;;
*.zip) unzip $1;;
*) echo "extract: '$1' - unknown archive method"; exit 1;;
esac
else
echo "$1 - file not found"
exit 1
fi
fi
}
extract $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment