LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 06-16-2006, 02:44 AM   #1
adamrosspayne
LQ Newbie
 
Registered: Jun 2006
Posts: 19

Rep: Reputation: 0
how to unzip all files with a wildcard path?


On my hard drive i have zip files scattered here and there. I can find them easily enough by doing a
find . -name "*.zip"

this list the path names to each zip archive.

However i want to be able to pipe this somehow to the unzip command so that i can unzip each of these files in the directories that they are allready found.

The unzip command say that it cannot take a wildcard as a path to the zip files. What can i do?

Any help appreciated :-)
 
Old 06-16-2006, 03:00 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi, and welcome to LQ!

find . -name "*.zip" -exec unzip {} \;

[edit]
Ooops ... I just read it again; my command will
unzip everything to the current dir. I'll think
again :}
[/edit]

[edit2]
A little script will do it...
Code:
#!/bin/bash
IFS='
'
FILE=$@
DIR=`dirname $FILE`
gunzip $FILE -d $DIR
Save that to some name and then use that
with the find statement above ... :}
[/edit2]


Cheers,
Tink

Last edited by Tinkster; 06-16-2006 at 04:06 AM.
 
Old 06-16-2006, 03:50 AM   #3
binary_y2k2
Member
 
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Blog Entries: 1

Rep: Reputation: 31
how about:
Code:
for i in `find . -name "*.zip"`;do f=$(basename $i); cd `echo $i|sed s/$f/''/`; unzip $f;cd -;done
that should unzip in the directory the zip files are in.
 
Old 06-16-2006, 04:52 AM   #4
LzW-x
Member
 
Registered: Jun 2006
Distribution: SuSe
Posts: 66

Rep: Reputation: 15
What I would really like to see is WinRAR for Linux (LinRAR?) not just in the terminal, but a full blown gui application like they have for windows!

The program does a ton of things by a single mouse click and it would be cool if that functionality was extended accross all modern GUI's!
 
Old 06-20-2006, 01:42 AM   #5
adamrosspayne
LQ Newbie
 
Registered: Jun 2006
Posts: 19

Original Poster
Rep: Reputation: 0
Thankyou everyone. I didnt understand the first solution so i tried this one form binary_y2k2

for i in `find . -name "*.zip"`;do f=$(basename $i); cd `echo $i|sed s/$f/''/`; unzip $f;cd -;done

it works great for files of the format blah.zip but not files of windows long naming convention like blarty blah.zip

I get an error saying unzip couldnt find or open blarty.zip and blah.zip. Any ideas on what we need to fix/
 
Old 06-20-2006, 03:18 AM   #6
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
The space in the filename is what confuses your shell.
You'll need to set the IFS variable (as in Tinkster's solution) to make your shell not split up the results
of your "find" on spaces, only on newlines.

Last edited by timmeke; 06-20-2006 at 03:22 AM.
 
Old 06-20-2006, 03:57 AM   #7
adamrosspayne
LQ Newbie
 
Registered: Jun 2006
Posts: 19

Original Poster
Rep: Reputation: 0
Thanks, so if originally we start with

find . -name "*.zip" -exec unzip {} \;

and call the script littlescript

then whereabouts do i enter littlescipt in the find argument line...
like this?
find . -name "*.zip" -exec unzip littlescript
 
Old 06-20-2006, 04:19 AM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by adamrosspayne
Thanks, so if originally we start with

find . -name "*.zip" -exec unzip {} \;

and call the script littlescript

then whereabouts do i enter littlescipt in the find argument line...
like this?
find . -name "*.zip" -exec unzip littlescript
Code:
 find . -name "*.zip" -exec littlescript {} \;
Cheers,
Tink
 
Old 06-20-2006, 04:20 AM   #9
adamrosspayne
LQ Newbie
 
Registered: Jun 2006
Posts: 19

Original Poster
Rep: Reputation: 0
whoops. ok i found that the following:

find . -name "*.zip" -exec littlescript {} \;

produced:
gunzip: ./Blarty blah.zip: unknown suffix -- ignored
gunzip: . is a directory -- ignored.

getting closer huh?
 
Old 06-20-2006, 04:28 AM   #10
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Quote:
gunzip: ./Blarty blah.zip: unknown suffix -- ignored
gunzip: . is a directory -- ignored.
Those are just gunzip warnings telling you that it can't unzip a directory or a file that doesn't have .gz, .zip, ... filename extension.
You can safely ignore those.
 
Old 06-20-2006, 04:31 AM   #11
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Not sure why unzip is complaining, but try this in the script:
Code:
#!/bin/bash
IFS='
'
PARAM=$@
DIR=`dirname $PARAM`
FILE=`basename $PARAM`
cd $DIR
unzip $FILE

Cheers,
Tink
 
Old 06-20-2006, 08:46 AM   #12
adamrosspayne
LQ Newbie
 
Registered: Jun 2006
Posts: 19

Original Poster
Rep: Reputation: 0
finally, it goes a little something like this...
#!/bin/bash
IFS='
'
PARAM=$@
DIR=`dirname $PARAM`
FILE=`basename $PARAM`
cd $DIR
mkdir `basename $PARAM .zip`
unzip $FILE -d `basename $PARAM .zip`
rm $FILE

This way the unzipped files end up in a directory named after the archive name. Thanks one and all :-)
 
Old 06-20-2006, 01:16 PM   #13
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Very good :}


Cheers,
Tink
 
  


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 14 08-29-2014 11:46 AM
using curl to DL files from HTTP sites with wildcard dehuszar Programming 7 09-03-2009 04:52 AM
about unzip to unzip some chinese files' trouble arcow Linux - Software 0 03-24-2006 02:25 AM
how do I unzip .gz files? triumdh Linux - Newbie 2 07-31-2005 05:26 PM
how to unzip files of this type andrewnow Linux - Software 4 03-14-2005 10:28 AM


All times are GMT -5. The time now is 12:20 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration