I am downloading a zip file which has a very deep nested structure from which I just need to pick a few files. The file structure looks like this:

C*_01.zip, ....., C*_xx.zip/

In each C*_xx.zip file:


Please note that on each "C*.zip" I need to pick the target file.

I do not have much experience with shell scripting so I have written a script based on other solutions but it doesn't work. I would appreciate any hint:

wget url | find . -name "myfile.zip" | while ["`find -type f -name 'C*.zip' | wc -l`" -gt 0 ]; do find -type f -name "b.zip" | find -type f -name "targetfile.txt" exec unzip -- '{}' \;; done
  • You want to extract targetfile.txt from all C*.zip archives contained in the myfile.zip archive? – ingopingo Feb 21 '17 at 18:56
  • @ingopingo yes, exactly – nopeva Feb 21 '17 at 20:18

Create a script file like fetchtarget.sh and start it with the URL as first argument.


dir=$(mktemp -d)
cd $dir || exit

wget $1

# deep unzip loop
while true; do
   find -iname '*.zip' > zipindex
   test -s zipindex || break
   for zip in $(cat zipindex); do unzip -o $zip && rm $zip; done

# purge and show result
find $dir -name targetfile.txt -print -or -type f -exec rm {} \; 
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.