Skip to content

Instantly share code, notes, and snippets.

@Blayung
Last active July 1, 2024 08:24
Show Gist options
  • Save Blayung/446fd03f61455e64d2769548522ff571 to your computer and use it in GitHub Desktop.
Save Blayung/446fd03f61455e64d2769548522ff571 to your computer and use it in GitHub Desktop.
bash extractor - a simple bash script to extract most common archive types
#!/bin/bash
if [ -z "$1" ]; then
echo "No file name was specified."
exit
elif ! [ -z "$2" ]; then
echo "Usage: extract.sh <filename>"
exit
elif ! [ -f "$1" ]; then
echo "This file does not exist."
exit
fi
if [[ $1 =~ ^.*\.(zip)$ ]]; then
unzip "$1"
elif [[ $1 =~ ^.*\.(rar)$ ]]; then
rar x "$1"
elif [[ $1 =~ ^.*\.(tar|tgz|tar.gz|txz|tar.xz|tar.bz2)$ ]]; then
tar -xf "$1"
else
echo "The specified file has an unrecognized file extension."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment