LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-15-2010, 08:31 PM   #1
linuxhippy
Senior Member
 
Registered: Sep 2004
Location: Philadelphia, PA
Distribution: Xubuntu, Mythbuntu, Lubuntu, Picuntu, Mint 18.1, Debian Jessie
Posts: 1,207

Rep: Reputation: 47
unzip many files...each zip file needs a directory


I have about 50 zip files that are all in 1 directory. How can I unzip these so that each zip file gets it's own directory?
 
Old 01-15-2010, 09:49 PM   #2
cantab
Member
 
Registered: Oct 2009
Location: England
Distribution: Kubuntu, Ubuntu, Debian, Proxmox.
Posts: 553

Rep: Reputation: 115Reputation: 115
Code:
for filename in *.zip ; do mkdir ${filename}.dir ; cd ${filename}.dir ; mv ../${filename} . ; unzip ${filename} ; cd .. ; done
results in ugly directory names I know, but otherwise works.
 
Old 01-15-2010, 09:57 PM   #3
linuxhippy
Senior Member
 
Registered: Sep 2004
Location: Philadelphia, PA
Distribution: Xubuntu, Mythbuntu, Lubuntu, Picuntu, Mint 18.1, Debian Jessie
Posts: 1,207

Original Poster
Rep: Reputation: 47
that worked well...any idea how to remove .zip.dir from all those directories?
 
Old 01-15-2010, 10:16 PM   #4
lwasserm
Member
 
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184

Rep: Reputation: 41
"just in case" backup your original zip files tile your done.

cd to the containing directory

for DIR in *.zip.dir; do echo ${DIR##.zip.dir};done

If it produces the names you want, change the do... statement as follows:


for DIR in *.zip.dir; do mv $DIR ${DIR##.zip.dir}; done
 
Old 01-15-2010, 10:30 PM   #5
linuxhippy
Senior Member
 
Registered: Sep 2004
Location: Philadelphia, PA
Distribution: Xubuntu, Mythbuntu, Lubuntu, Picuntu, Mint 18.1, Debian Jessie
Posts: 1,207

Original Poster
Rep: Reputation: 47
nope...I got this error:

mv: cannot move `xmms-256.zip.dir' to a subdirectory of itself, `xmms-256.zip.dir/xmms-256.zip.dir'
 
Old 01-15-2010, 11:03 PM   #6
linuxhippy
Senior Member
 
Registered: Sep 2004
Location: Philadelphia, PA
Distribution: Xubuntu, Mythbuntu, Lubuntu, Picuntu, Mint 18.1, Debian Jessie
Posts: 1,207

Original Poster
Rep: Reputation: 47
maybe cut -c .zip.dir goes in there??
 
Old 01-17-2010, 11:20 AM   #7
lwasserm
Member
 
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184

Rep: Reputation: 41
Sorry, should have used %% instead of ##. Corrected version would be:

for DIR in *.zip.dir; do mv $DIR ${DIR%%.zip.dir}; done

It still be advisable to test for the desired names first with

for DIR in *.zip.dir; do echo ${DIR%%.zip.dir}; done

before doig the actual name change with "mv"
 
Old 01-17-2010, 01:15 PM   #8
cantab
Member
 
Registered: Oct 2009
Location: England
Distribution: Kubuntu, Ubuntu, Debian, Proxmox.
Posts: 553

Rep: Reputation: 115Reputation: 115
What exactly does the %% do then? It's not something I've come across in bash before.
 
Old 01-17-2010, 03:56 PM   #9
lwasserm
Member
 
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184

Rep: Reputation: 41
From the bash man page:
Code:
 ${parameter%word}
 ${parameter%%word}
              The word is expanded to produce a pattern just  as  in  pathname
              expansion.   If  the  pattern  matches a trailing portion of the
              expanded value of parameter, then the result of the expansion is
              the  expanded value of parameter with the shortest matching pat‐
              tern (the ‘‘%’’ case)  or  the  longest  matching  pattern  (the
              ‘‘%%’’  case)  deleted.   If  parameter  is  @ or *, the pattern
              removal operation is applied to  each  positional  parameter  in
              turn,  and the expansion is the resultant list.  If parameter is
              an array variable subscripted with @ or *, the  pattern  removal
              operation  is  applied  to each member of the array in turn, and
              the expansion is the resultant list.
Look in the "Parameter Expansion" section
 
Old 01-17-2010, 04:36 PM   #10
cantab
Member
 
Registered: Oct 2009
Location: England
Distribution: Kubuntu, Ubuntu, Debian, Proxmox.
Posts: 553

Rep: Reputation: 115Reputation: 115
That extract from the man page is one of the most confusing things I have ever read...I understood it, eventually, after reading through it like 5 times.
 
Old 01-17-2010, 05:08 PM   #11
lwasserm
Member
 
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184

Rep: Reputation: 41
Quote:
Originally Posted by cantab View Post
That extract from the man page is one of the most confusing things I have ever read...I understood it, eventually, after reading through it like 5 times.
Wow, good for you! I'm sure I had to read it 8 or 9 times myself!
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unzip all .zip files in a directory tes15 Linux - Newbie 14 08-29-2014 11:46 AM
Help to unzip more than one *.zip files SanaJay Linux - Newbie 5 02-10-2009 12:31 AM
Need help to unzip a .zip file with 2 files in it SanaJay Linux - Newbie 3 02-05-2009 02:43 AM
Why cann't unzip a .zip file? backpacker Linux - Newbie 1 02-05-2006 09:25 PM
How to Unzip 2 Zip files through one single command sumitarun Linux - Newbie 2 03-23-2005 08:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:28 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration