On Tue, Mar 01, 2005 at 04:31:52PM +0800, Chris Purves wrote: > I would like to unzip a .zip file and maintain the permissions and > ownership of the .zip file. > > I can't find a switch for the unzip command. Is there a way to do it? > > -- > Take care, eh. > Chris > > Hi Chris, I'll give it a shot, though I don't how what you want to could be really useful...with my default rights, I am not able to give ownership to another user usually... Here goes, a small script which does --- 8< ----------------------------------------------------------------- #!/bin/bash # Usage: 'zipchange.sh archive', where archive.zip expands to archive ZIPUSER=`ls -l $1.zip |awk '{print $3}'` ZIPGROUP=`ls -l $1.zip |awk '{print $4}'` unzip $1.zip chown -R $ZIPUSER.$ZIPGROUP $1 --- 8< ----------------------------------------------------------------- Obviously, there are some restraints here. First, the extracted archive has to have its starting directory being the same as the archive name. Also the naming with '$1.zip' is not very nice. But generally it works. 'zipchange.sh archive' will unzip archive.zip and chown the resulting 'archive' to the owner of archive.zip -- that is, _if_ the chown operation is permitted, which I assume. Enhance to liking. Hth, -- Andreas Rippl -- GPG messages preferred Key-ID: 0x81073379
Attachment:
signature.asc
Description: Digital signature