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 :-) |
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 with the find statement above ... :} [/edit2] Cheers, Tink |
how about:
Code:
for i in `find . -name "*.zip"`;do f=$(basename $i); cd `echo $i|sed s/$f/''/`; unzip $f;cd -;done |
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! |
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/ |
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. |
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 |
Quote:
Code:
find . -name "*.zip" -exec littlescript {} \; Tink |
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? |
Quote:
You can safely ignore those. |
Not sure why unzip is complaining, but try this in the script:
Code:
#!/bin/bash Cheers, Tink |
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 :-) |
Very good :}
Cheers, Tink |
All times are GMT -5. The time now is 09:04 AM. |