Created
March 24, 2023 19:54
-
-
Save MLKrisJohnson/a220e601d1278b7065c0fb05d49a3d4a to your computer and use it in GitHub Desktop.
Bash/Zsh function to decompress a set of files into a subdirectory
This file contains hidden or 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
# Unzip a set of files to an "unzipped" subdirectory | |
# | |
# Example: | |
# | |
# unzipped *.zip *.tar.gz | |
# | |
# will create the "unzipped" directory if not present, and decompress all the files into that directory. | |
function unzipped { | |
for f in "$@" ; do | |
directory=$(dirname "$f") | |
base=$(basename "$f") | |
filename=${base%.*} | |
mkdir -p "$directory/unzipped" | |
echo "$f" | |
if [[ $f = *.tar.gz ]]; then | |
filename=${filename%.*} # strip off the remaining ".tar" suffix | |
mkdir -p "$directory/unzipped/$filename" | |
/usr/bin/tar -zxv -C "$directory/unzipped/$filename" -f "$f" | |
else | |
/usr/bin/unzip -o -d "$directory/unzipped/$filename" "$f" | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment