用xargs和tar查找 [英] find with xargs and tar

查看:342
本文介绍了用xargs和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 = -


即排除一大堆东西,只看6个subdirs深度,然后一次修剪完成后,其余的事情。不是很难。管道(|)之前的位工作100%。如果我排除焦油,那么我得到我以后(到屏幕上)。但是,一旦我包括管道和焦油,它就会把所有东西都包括在内,包括我在发现中排除的所有东西。

我尝试了许多不同的迭代:

-print0 | xargs -0 tar rvf somefile.tar

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

-print0 | tar cvf somefile.tar --null -T -



那我做错了什么?我以前做过但现在它只是给我灰色头发。

解决方案

对我来说有效的是查找的-print标志和然后在tar命令中输入--files-from。在我的情况下,我需要tar超过5000个日志文件,但只是使用xargs只给了我500文件在结果文件。



 找到。 -name* .pdf-print | tar -czf pdfs.tar.gz --files-from  -  

你有--files-从 - =,当你只是想 - 文件 - 从 - ,然后我认为你需要一个 - 在前面的CVF,如下所示:

<$ p $找到> 。 -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 -


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 6 subdirs depth, and then once pruning is done, tar up the rest.

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.

解决方案

What worked for me is a combination of the -print flag for find, and then --files-from on the tar command. In my case I need 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 -

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆