Re: Extracting zipfiles in their own directory.

From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 11/10/05


Date: Wed, 9 Nov 2005 20:41:29 -0500

On 2005-11-10, Dave wrote:
> Dave wrote:
>> I have 14,000 zip files buried in numerous directories.
>>
>> find . -name '*.zip' | more
>> ./Sept 2000/Ph1/02_serie/0220-301.zip
[snip]
>> ./Sept 2000/Ph2/01_serie/0104-412.zip
>>
>> I'd like to exact all files from each zip file in the directory where
>> the zip file exists.
>>
>> This will not do
>>
>> find . -name '*.zip' -exec unzip {} \;
>>
>> as it extracts then all in the directory from where the command is run,
>> rather than the directory where an individual zip file is.
>>
>> Can anyone suggest how to do this in an automated fashion? I guess I
>> need to
>>
>> a) Find a directory.
>> b) change to that directory
>> c) unzip any .zip files in that directory
>> e) return and look for another directory.
>
> I have solved this at last. I suspect someone more competant could do it
> on the command line, rather than need a script,

   If it's something you do frequently, it belongs in a script.

> but this works.
>
> 1) Create a small script call 'uzip'
>
> sparrow /export/home/drkirkby/g % cat uzip
> #!/bin/sh
> cd $1
> unzip *.zip
>
> 2) Run find, trying to unzip the files in each and every directory using
> the script above. unzip creates an error message if there are no zip
> files in the directory, but it works on those where there is one or more.
>
> sparrow /export/home/drkirkby/g % find . -type d -exec uzip {} \; | more
> unzip: cannot find *.zip, *.zip.zip or *.zip.ZIP.
>
> No zipfiles found.
> unzip: cannot find *.zip, *.zip.zip or *.zip.ZIP.
>
> No zipfiles found.
> Archive: 198.zip
> inflating: apd/1998data/5-12-98/50mmc.dat
> inflating: apd/1998data/5-12-98/0mmb.dat
> inflating: apd/1998data/5-12-98/0mmc.dat

   You can prevent the error message with:

cd "${1:-/ZXZX}" || exit 1
set -- *.[Zz][Ii][Pp]
[ -f "$1" ] && unzip *.[Zz][Ii][Pp]

-- 
  Chris F.A. Johnson                   | Author:
  <http://cfaj.freeshell.org>          |      Shell Scripting Recipes:
  Any code in this post is released    |  A Problem-Solution Approach,
  under the GNU General Public Licence |                 2005, Apress


Relevant Pages

  • Re: Extracting zipfiles in their own directory.
    ... > c) unzip any .zip files in that directory ... on the command line, rather than need a script, but this works. ... No zipfiles found. ...
    (comp.unix.shell)
  • Re: OneCare Virus definitions
    ... | Dave, plase! ... however I have to write the script. ... if the "customer" is a company or corporation the product should not ... it would be professional malpractice NOT to point out these facts ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Commonly Trojaned Linux services
    ... >> the script was to have a very fast, ... > Dave Wreski ... There is no administration of reports unless there is a problem. ... w33n3r: Yeah. ...
    (comp.os.linux.security)
  • Re: Rewritten play
    ... playwright is the soul of the theatre and the writer's script is at the heart of what we do. ... To alter it to fit one's own concept is to be a traitor to the theatre. ... Dave: So, you'd be willing to give up evil for Lisa? ... Johnny Johnson: Teaching English as a second language. ...
    (rec.arts.theatre.plays)
  • Re: help with cpio
    ... Dave Calhoun wrote: ... > Currently my nightly backup is done by calling a backup script from ... That script get's it's variables from a config file and executes ... -- http://ftp.opensysmon.com is a shell script archive site with an open source system monitoring and network monitoring software package. ...
    (comp.unix.aix)

Quantcast