0

I've 4 folder & inside each of them, there're a folder XML that contain zip files & some folders with zip files

All of the zip files contains files in XML format

/A/XML/:
  BDL_DCR_20170216.zip
  BDL_BPR_20170218.zip
  .
  .
/A/XML/zipped:
  BDL_CPR_20170221.zip
  BDL_BPR_20170220.zip
  .
  .

/B/XML/:
  BDL_DCR_20170216.zip
  BDL_BPR_20170218.zip
  .
  .
/B/XML/20170221/:
  BDL_DCR_20170216.zip
  BDL_BPR_20170218.zip
  .
  .
/B/XML/zipped/:      BDL_DCR_20170216.zip
  BDL_BPR_20170218.zip
  .
  .

the rest with similar pattern

`/C/XML-20170221, *.zip`

`/D/XML-20170221, 20170220, 20170219`

I wanted to unzip all of it & save it to some directory X

I tried to unzip one of it by:

find /home/A/XML -type f -name "*.zip" | unzip /home/A/XML/*

& got the following error:

Archive:  /home/A/BDL_XM_20170221.zip
caution: filename not matched:  /home/A/XML/ZIPPED
caution: filename not matched:  /home/A/XML/20170221.zip

I'm thinking maybe there's something wrong with unzip /home/A/XML/* cause in simple case is unzip /home/A/XML/*.zip

Can anyone suggest how can I unzip all of the folders one shot? How can I unzip all the zip files & the folders with zip files?

Thanks a lot, appreciate your help :)

  • I don't understand your folder structure. Can you provide the actual output from ls -l in the relevant directories (truncate it, if there are too many lines). – EightBitTony Feb 21 '17 at 9:26
  • @EightBitTony Thanks for raising the question, I've edited my questions. Pls have a look. – Juliet.Y Feb 21 '17 at 9:40
2

Untested but try

find /home/A/XML -type f -name "*.zip" -exec unzip '{}' -d /target/path \;

Someone will be along in a bit to remind me to use xargs instead.

  • Quite the opposite: the basic rule of xargs is, use -exec instead. – Gilles Feb 21 '17 at 23:23
  • The code is working fine :) Thanks alot. I saw some people used -execdir instead, what is the different? – Juliet.Y Feb 22 '17 at 2:11
  • -execdir changes the working directory to the one in which the file is located before executing the command, -exec doesn't. The implications and uses might be worth a full answer rather than a comment - in which case, feel free to ask a new full question asking about the differences with your specific example above. – EightBitTony Feb 22 '17 at 13:38
  • @Gilles thanks, I went a did a bit more reading, I was sure the advice a few years ago was xargs by preference, but looks like I was mistaken! – EightBitTony Feb 22 '17 at 13:40

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.