LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to unzip all files with a wildcard path? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-unzip-all-files-with-a-wildcard-path-455311/)

adamrosspayne 06-16-2006 02:44 AM

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 :-)

Tinkster 06-16-2006 03:00 AM

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

binary_y2k2 06-16-2006 03:50 AM

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.

LzW-x 06-16-2006 04:52 AM

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!

adamrosspayne 06-20-2006 01:42 AM

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/

timmeke 06-20-2006 03:18 AM

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.

adamrosspayne 06-20-2006 03:57 AM

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

Tinkster 06-20-2006 04:19 AM

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

adamrosspayne 06-20-2006 04:20 AM

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?

timmeke 06-20-2006 04:28 AM

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.

Tinkster 06-20-2006 04:31 AM

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

adamrosspayne 06-20-2006 08:46 AM

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 :-)

Tinkster 06-20-2006 01:16 PM

Very good :}


Cheers,
Tink


All times are GMT -5. The time now is 09:04 AM.