tags:

views:

29

answers:

4
$ find /tmp/a1
/tmp/a1
/tmp/a1/b2
/tmp/a1/b1
/tmp/a1/b1/x1

simply trying

find /tmp/a1 -exec tar -cvf dirall.tar {} \;

simply doesn't work

any help

A: 

The command specified for -exec is run once for each file found. As such, you're recreating dirall.tar every time the command is run. Instead, you should pipe the output of find to tar.

find /tmp/a1 -print0 | tar --null -T- -cvf dirall.tar

Note that if you're simply using find to get a list of all the files under /tmp/a1 and not doing any sort of filtering, it's much simpler to use tar -cvf dirall.tar /tmp/a1.

jamessan
Or even tar -cvf \`find /tmp/a1\` now that I think about it :)Actually, if you tar /tmp/a1, you get it all anyway. I might be misunderstanding the problem.
barrycarter
Yeah, I was just assuming that the `find` was actually more complex and that the question had been boiled down to a simple scenario.
jamessan
A: 

I'd think something like "find /tmp/a1 | xargs tar cvf foo.tar" would work. But make sure you have backups first!

barrycarter
A: 

Does hpux have cpio ? That will take a list of files on stdin and some versions will write output in tar format.

Steven D. Majewski
A: 

You're one character away from the solution. Just replace the -c with -r to put tar into append mode so that each time find invokes it, it'll tack on one more file:

rm -f dirall.tar
find /tmp/a1 -exec tar -rvf dirall.tar {} \;
Rob Davis
You can only specify one "function" option. Here you have two -- `-c` and `-r`. Drop the `-c` (and quote or escape the `{}`) and it should work.
jamessan
Thanks for catching the typo -- I should have tried the command first. I've edited the answer to remove the -c option. Also, no need to escape the {} in a Bourne-based shell.
Rob Davis