“找到"与"xargs"和"tar" [英] 'find' with 'xargs' and 'tar'
问题描述
我要执行以下操作:
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.
这并不难.管道(|)之前的位有效100%.如果我排除焦油",那么我将得到(屏幕上)想要的东西.但是一旦我把管道和焦油包括在内,它就会使所有东西都焦油,包括我刚刚在查找"中排除的所有东西.
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.
推荐答案
-print
标志的组合,用于查找,然后在-files-from
'tar'命令对我有用.就我而言,我需要压缩5000多个日志文件,但是仅使用'xargs'只能在生成的文件中提供500个文件.
A combination of the -print
flag for find, and then --files-from
on the 'tar' command worked for me. In my case I needed to tar up 5000+ log files, but just using 'xargs' only gave me 500 files in the resulting file.
find . -name "*.pdf" -print | tar -czf pdfs.tar.gz --files-from -
当您只想"--files-from-"时,您有"--files-from =-".然后我认为您需要在 cvf
前面的-
,如下所示.
You have "--files-from=-", when you just want "--files-from -" and then I think you need a -
in front of cvf
, like the following.
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.gz --files-from -
这篇关于“找到"与"xargs"和"tar"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!