Take the 2-minute tour ×
$ find /tmp/a1

simply trying

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

simply doesn't work

any help

share|improve this question

4 Answers 4

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.

share|improve this answer
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 Jun 2 '10 at 14:22
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 Jun 2 '10 at 14:42

You're one character away from the solution. The find command's exec option will execute the command for each file found, so you should replace -c with -r to put tar into append mode. Each time find invokes it, it'll tack on one more file:

rm -f dirall.tar
find /tmp/a1 -exec tar -rvf dirall.tar {} \;
share|improve this answer
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 Jun 2 '10 at 20:15
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 Jun 2 '10 at 21:45

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

share|improve this answer

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

share|improve this answer

Your Answer


