Reputation: 369
I have a directory with a bunch of zip archives (mixed in with other files) that are encrypted with the same password. I want to find all the zip files and unzip them in the directory that the zip file is located in.
So far I have:
find -type f -name "*.zip" -exec sh -c 'unzip -pPASSWORD -d `dirname {}` {}' ';'
But I get the error
error: must specify directory to which to extract with -d option
All help appreciated. Thank you
Upvotes: 3
Views: 1387
Reputation: 5591
Try with this, also see my comment in the scripts how will it work:-
find -type f -name "*.zip" > zipfiles.txt
while read zipfilePath
do
directorypath=${zipfilePath%/*}
#get the path and separate the zipfile name
zipfile=${zipfilePath##*/}
#get the zipfile name from path
cd $directorypath
unzip -pPASSWORD $zipfile
done < zipfiles.txt
rm -rf zipfiles.txt
Upvotes: 1