Help using find command

K. Reid Wightman reidkr at spawar.navy.mil
Tue Oct 31 22:14:44 UTC 2006


Rob Myroon wrote:
> Hi list,
> 
> I am trying to tar up all the openoffice files on my server using the 
> find command. The command I have come up with only tars the last file 
> found by the find command.
> 
> # find . -regex '.*\(odt\|ods\|sxc\)$' -exec cvzf 
> /root/openofficefiles.tar.gz {} \;

Looking at the man page, it isn't really clear that exec doesn't work 
how you probably think it works.

What's happening is, each file found is getting a separate tar instance 
run on it.  That is, say 'find' finds two files a.odt and b.odt.  First 
exec runs 'tar cvzf /root/openofficefiles.tar.gz a.odt' then exec runs 
'tar cvzf /root/openofficefiles.tar.gz b.odt'.

 > Can someone tell me how to make this work? (I realize that there are
 > more openoffice extensions.)

I would suggest trying:

tar -c /root/openofficefiles.tar && find . -regex 'fancy-regex-foo' 
-exec tar -rv {} \;

This will create the empty archive, then find the files and append them 
one-at-a-time to the end of the tarfile.  It may be possible to append 
to a zipped tar archive, but I am not certain.

Reid
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 4062 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://listman.redhat.com/archives/redhat-sysadmin-list/attachments/20061031/493fc6dd/attachment.bin>


More information about the redhat-sysadmin-list mailing list