管道查找查找
我想将查找结果通过管道传输到新查找。我所得到的是:
find . -iname "2010-06*" -maxdepth 1 -type d | xargs -0 find '{}' -iname "*.jpg"
预期结果:第二个查找收到从 2010-06 开始的文件夹列表,第二个查找返回这些文件夹中包含的 jpg 列表。
实际结果:“查找:./2010-06 纽约\n:未知选项”
哦,该死。我有一种感觉,它涉及第二个查找作为输入接收的输出格式,但我唯一的想法是将 -print0 后缀添加到第一个查找,没有任何更改。
有什么想法吗?
I want to pipe a find result to a new find. What I have is:
find . -iname "2010-06*" -maxdepth 1 -type d | xargs -0 find '{}' -iname "*.jpg"
Expected result: Second find receives a list of folders starting with 2010-06, second find returns a list of jpg's contained within those folders.
Actual result: "find: ./2010-06 New York\n: unknown option"
Oh darn. I have a feeling it concerns the format of the output that the second find receives as input, but my only idea was to suffix -print0 to first find, with no change whatsoever.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你需要两件事。
-print0
,更重要的是 xargs 上的-I{}
,否则{}
不会执行任何操作。You need 2 things.
-print0
, and more importantly-I{}
on xargs, otherwise the{}
doesn't do anything.xargs 的使用毫无用处。
至少 Gnu-find 接受多个路径进行搜索。隐式假定 -maxdepth 和类型 -d。
Useless use of xargs.
At least Gnu-find accepts multiple paths to search in. -maxdepth and type -d is implicitly assumed.
等等怎么样
?
How about
etc?
尽管您确实说过您特别希望解决此 find + pipeline 问题,但分叉额外的
find
命令效率很低。由于您将 -maxdepth 指定为 1,因此您不会遍历子目录。因此,只需使用带有 shell 扩展的for
循环即可。如果您想递归地查找每个 2010-06* 文件夹内的所有 jpg 文件,也无需使用多个
finds
或xargs
或者只是
find 2006- 06* -type f -iname "*.jpg"
或者更好,如果你有 bash 4 及以上版本
Although you did say that you specifically want this find + pipe problem to work, its inefficient to fork an extra
find
command. Since you are specifying -maxdepth as 1, you are not traversing subdirectories. So just use afor
loop with shell expansion.If you want to find all jpg files inside each 2010-06* folders recursively, there is also no need to use multiple
finds
orxargs
Or just
find 2006-06* -type f -iname "*.jpg"
Or even better, if you have bash 4 and above