开发者

tarring find results on hp-ux

$ find /tmp/a1
/tmp/a1
/tmp/a1/b2
/tmp/a1/b1
/tmp/a1/b1/x开发者_Python百科1

simply trying

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

simply doesn't work

any help


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.


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 {} \;


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜