Skip to content

Instantly share code, notes, and snippets.

@nknote
Created June 11, 2016 15:36
Show Gist options
  • Save nknote/b160adf819078a5d90a682f5f2eaf59e to your computer and use it in GitHub Desktop.
Save nknote/b160adf819078a5d90a682f5f2eaf59e to your computer and use it in GitHub Desktop.
Find all zip files in current folder and subfolders and extract the contents in a folder with the zip file name.
#!/bin/bash
rootdir="$PWD"
find "$rootdir" -type f -name '*.zip' | while read file;do # find all .zip files in the directory
cd "$(dirname "$file")"
if [ "$(dirname "$file")" = "$PWD" ];then # if the file found is in the same directory as defined "rootdir"
mkdir "$(basename "$file" | cut -d. -f1)"
cd "$(basename "$file" | cut -d. -f1)"
unzip -O cp949 -n "$file" # unzip the file
mv "$file" "$file".tododelete
else
echo "error"
break
fi
done
cd "$rootdir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment