Skip to content

Instantly share code, notes, and snippets.

@koraysels
Created December 14, 2023 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koraysels/e39658b7d3d4d26abcd60de6a7467291 to your computer and use it in GitHub Desktop.
Save koraysels/e39658b7d3d4d26abcd60de6a7467291 to your computer and use it in GitHub Desktop.
unzip all zip files in folder and use the zip archive name as the folder root
#!/bin/bash
for zipFile in *.zip; do
fileName=$(basename "$zipFile" .zip)
echo "Extracting $zipFile..."
unzip -q "$zipFile" -d "$fileName"
newName=$(echo "$fileName" | cut -d '_' -f 1)
# Move the contents of the inner folder to the parent folder
mv "$fileName"/* "$newName"/
# Remove the now-empty inner folder
rmdir "$fileName"
done
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment