Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sorry this question is trivial, but I couldn't get it to work: I have a folder full of .zip files, each .zip file contains exactly one .xml file. The zip files have sensible names like a.zip etc., while the .xml file contained in them have some "randomname".xml

Now I want to unpack all the .zip files in the folder, preserving the name of the .zip files, so that a.zip gets unpacked into a.xml, b.zip into b.xml etc...

I only managed to achieve a batch unpacking with the command:

for z in *.zip; do unzip "$z"; done How do I enhance this to keep the names?

share|improve this question

1 Answer 1

Assuming you don't have any .xml files in that directory when you start and each .zip only has exactly one .xml file, you could do this.

for z in *.zip; do
   unzip $z
   mv *.xml `echo $z | sed "s/\.zip$/.xml/"`
done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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