Skip to content

Instantly share code, notes, and snippets.

@zxjinn
Created January 18, 2013 06:09
Show Gist options
  • Save zxjinn/4562693 to your computer and use it in GitHub Desktop.
Save zxjinn/4562693 to your computer and use it in GitHub Desktop.
Finds all zip files in the current directory, and its sub-directories, then unzips them into folders in the current directory that are named the same as the zip files and sub-directory names. For example: ./subdir/file.zip -> ./subdir_file/extractedfile. Tested on Ubuntu 12.04 with Unzip 6.00.
#!/bin/bash
# Extracts all zipfiles in subdirectories to current directory.
for source in $(find . -name "*.zip")
do
unzip -tq $source
retval=$?
if [ $retval -eq 0 ]
then
dest=$(echo $source | sed -e 's|.zip||g' -e 's|/|_|g' -e 's|\._||g')
unzip -u $source -d $dest
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment