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? |
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 Now we sit and wait for someone to pick apart my terrible scripting skills :D |
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 |
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. |