Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have many zip files a.zip, b.zip, c.zip, ... and I want to extract each of them into new folders a, b, c, ... respectively, via ubuntu terminal. Actually, what I want is a solution that I can use later with a find because I actually have many folders 2014, 2013, 2012, ... each of them containing many zip files a.zip, b.zip, etc. If I do find . -name "*.zip" -exec {} unzip \; it will unzip all the files and put them into their respective parent folder.

share|improve this question
up vote 21 down vote accepted

You should be able to use unzip's -d option to set an alternate directory for the archive contents.

unzip -d a a.zip
unzip -d b b.zip

and so on. Within a find expression, you should be able to derive the name for the directory from the name of the zipfile using shell parameter expansion e.g.

find -name '*.zip' -exec sh -c 'unzip -d "${1%.*}" "$1"' _ {} \;

Test it first by adding an echo i.e.

find -name '*.zip' -exec sh -c 'echo unzip -d "${1%.*}" "$1"' _ {} \;

or something like

while read -rd $'\0' f; do 
  unzip -d "${f%.*}" "$f"
done < <(find -name '*.zip' -print0)
share|improve this answer
2  
Works perfectly. Could you explain what is the command doing? Specifically the -exec part. – Michael Aug 31 '14 at 13:41

Simply Use

unzip '*.zip' -d /home/user/folder/
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.