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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
01-15-2010, 08:31 PM
|
#1
|
|
Senior Member
Registered: Sep 2004
Location: Philadelphia, PA
Distribution: Fedora Core, Slackware, Vector Linux, Ubuntu
Posts: 1,167
Rep:
|
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?
|
|
|
|
01-15-2010, 09:49 PM
|
#2
|
|
Member
Registered: Oct 2009
Location: England
Distribution: *buntu, Vector
Posts: 495
Rep: 
|
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.
|
|
|
|
01-15-2010, 09:57 PM
|
#3
|
|
Senior Member
Registered: Sep 2004
Location: Philadelphia, PA
Distribution: Fedora Core, Slackware, Vector Linux, Ubuntu
Posts: 1,167
Original Poster
Rep:
|
that worked well...any idea how to remove .zip.dir from all those directories?
|
|
|
|
01-15-2010, 10:16 PM
|
#4
|
|
Member
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184
Rep:
|
"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
|
|
|
|
01-15-2010, 10:30 PM
|
#5
|
|
Senior Member
Registered: Sep 2004
Location: Philadelphia, PA
Distribution: Fedora Core, Slackware, Vector Linux, Ubuntu
Posts: 1,167
Original Poster
Rep:
|
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'
|
|
|
|
01-15-2010, 11:03 PM
|
#6
|
|
Senior Member
Registered: Sep 2004
Location: Philadelphia, PA
Distribution: Fedora Core, Slackware, Vector Linux, Ubuntu
Posts: 1,167
Original Poster
Rep:
|
maybe cut -c .zip.dir goes in there??
|
|
|
|
01-17-2010, 11:20 AM
|
#7
|
|
Member
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184
Rep:
|
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"
|
|
|
|
01-17-2010, 01:15 PM
|
#8
|
|
Member
Registered: Oct 2009
Location: England
Distribution: *buntu, Vector
Posts: 495
Rep: 
|
What exactly does the %% do then? It's not something I've come across in bash before.
|
|
|
|
01-17-2010, 03:56 PM
|
#9
|
|
Member
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184
Rep:
|
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
|
|
|
|
01-17-2010, 04:36 PM
|
#10
|
|
Member
Registered: Oct 2009
Location: England
Distribution: *buntu, Vector
Posts: 495
Rep: 
|
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.
|
|
|
|
01-17-2010, 05:08 PM
|
#11
|
|
Member
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184
Rep:
|
Quote:
Originally Posted by cantab
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! 
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 08:54 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|