LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-13-2005, 01:04 AM   #1
smart_sagittari
LQ Newbie
 
Registered: Apr 2005
Posts: 26

Rep: Reputation: 16
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?
 
Old 04-13-2005, 01:16 AM   #2
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
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

Last edited by scuzzman; 04-13-2005 at 01:22 AM.
 
1 members found this post helpful.
Old 04-13-2005, 01:50 AM   #3
smart_sagittari
LQ Newbie
 
Registered: Apr 2005
Posts: 26

Original Poster
Rep: Reputation: 16
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!
 
1 members found this post helpful.
Old 03-21-2012, 08:41 AM   #4
extremus
LQ Newbie
 
Registered: Mar 2012
Posts: 1

Rep: Reputation: Disabled
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unzip all .zip files in a directory tes15 Linux - Newbie 12 08-08-2005 02:25 PM
How to Unzip 2 Zip files through one single command sumitarun Linux - Newbie 2 03-23-2005 08:00 AM
How to unzip all the src files in linux src folder? raj_ice Linux - Newbie 1 10-15-2004 09:46 AM
Zip and Unzip concoran Linux - General 4 08-02-2002 07:12 PM
how do i unzip a .zip? lax2sman Linux - General 2 02-11-2002 05:17 PM


All times are GMT -5. The time now is 11:25 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration