Re: Extracting zipfiles in their own directory.
From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 11/10/05
- Next message: Sven Mascheck: "Re: hpux 11 here document problem"
- Previous message: base60: "Re: UNIX Lockfiles"
- In reply to: Dave: "Re: Extracting zipfiles in their own directory."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Sven Mascheck: "Re: hpux 11 here document problem"
- Previous message: base60: "Re: UNIX Lockfiles"
- In reply to: Dave: "Re: Extracting zipfiles in their own directory."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|