Last active
July 1, 2024 08:24
-
-
Save Blayung/446fd03f61455e64d2769548522ff571 to your computer and use it in GitHub Desktop.
bash extractor - a simple bash script to extract most common archive types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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