'find' with 'xargs' and 'tar'

Viewed 26006

I have the following I want to do:

find . -maxdepth 6 \( -name \*.tar.gz -o -name bediskmodel -o -name src -o -name ciao -o -name heasoft -o -name firefly -o -name starlink -o -name Chandra \) -prune -o -print | tar  cvf somefile.tar --files-from=-

I.e., exclude a whole lot of stuff, only look to six subdirectories depth, and then once pruning is done, 'tar' up the rest.

It is not hard. The bit before the pipe (|) works 100%. If I exclude the 'tar', then I get what I'm after (to the screen). But once I include the pipe, and the tar, it tars everything, including all the stuff I've just excluded in the 'find'.

I've tried a number of different iterations:

-print0 | xargs -0 tar rvf somefile.tar
-print0 | xargs -0 tar rvf somefile.tar --null --files-from=-
-print0 | tar cvf somefile.tar --null -T -

So what am I doing wrong? I've done this before; but now it's just giving me grey hairs.

6 Answers

This work for me, where ARG can be any name var

find . -name "*.tar.gz" -print | xargs -I ARG tar -xvzf ARG

...

Related