Extract any archive in one command
A universal extract function you can add to ~/.bashrc — handles tar.gz, zip, bz2, 7z and more.
$ extract() {
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.tar.xz) tar xJf "$1" ;;
*.zip) unzip "$1" ;;
*.7z) 7z x "$1" ;;
*.gz) gunzip "$1" ;;
*) echo "Unknown format: $1" ;;
esac
}
# Usage:
extract archive.tar.gz
bashscripter2026-04-19
Delete this trick? This cannot be undone.