LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Unzip multiple zip files, each to separate folder (https://www.linuxquestions.org/questions/linux-newbie-8/unzip-multiple-zip-files-each-to-separate-folder-312646/)

smart_sagittari 04-13-2005 01:04 AM

Unzip multiple zip files, each to separate folder
 
I have a set of zip files, 123_1.zip, 123_2.zip, and 123_3.zip in a particular folder. I need to unzip each of these zip files to a separate folder as follows:

123_1.zip ==> 123_1
123_2.zip ==> 123_2
123_3.zip ==> 123_3

My problem is, I need to do this whole thing using a *single* command, something like the 'Extract each file to separate folder' option present in WinZip.

Any suggestions?

scuzzman 04-13-2005 01:16 AM

You'll want to do something like this (try this on test files -- I haven't got a box to test it on right now):
Code:

for file in `ls | grep 123`; do unzip $file -d `echo $file | cut -d . | grep 123`; done
Something like that... Don't know if that'll work or not...
Now we sit and wait for someone to pick apart my terrible scripting skills :D

smart_sagittari 04-13-2005 01:50 AM

Brilliant! It worked. Just a small change had to be done.

Code:

for file in `ls 123_*.zip'; do unzip $file -d `echo $file | cut -d "." -f 1`; done
Thanks a lot!

extremus 03-21-2012 08:41 AM

minimalistic error in the previous post
 
Great! This just saved me a lot of time compared to figuring it out by myself. Thanks to the authors!
Although this response is a little late, those that come here from a web search might save another minute with this very tiny correction: There is one "'" instead of "`" in smart_sagittari's code. Here's what I used (for arbitrarily named zip files):

Code:

for file in `ls *.zip`; do unzip $file -d `echo $file | cut -d . -f 1`; done


All times are GMT -5. The time now is 06:38 PM.