庆典 - 什么是计算发现,效果最好的方法是什么? [英] bash - What is the best way to count find-results?
问题描述
我目前的解决办法是找到<&expr的GT; -exec printf的'。 \\; | WC -c
,但这需要时间太长时,有超过10000项。有没有更快/更好的方式来做到这一点?
My current solution would be find <expr> -exec printf '.' \; | wc -c
, but this takes far too long when there are more than 10000 results. Is there no faster/better way to do this?
编辑://貌似没有 -count
我失踪。不过,也有3 downvotes,我不知道为什么。能否请您发表评论,所以我可以提高我的问题?
//Seemingly, there is no -count
I'm missing. However, there are 3 downvotes and I have no idea why. Could you please leave comments so I can improve my question?
推荐答案
为什么不
find <expr> | wc -l
作为一个简单的便携式解决方案?您的原始方案是的产卵一个新的进程的的printf
每一个人的文件中找到,这是非常昂贵的(因为你刚发现)。
as a simple portable solution ? Your original solution is spawning a new process printf
for every individual file found, and that's very expensive (as you've just found).
请注意,如果你有一个嵌入式换行符的文件名,这将超量的,但如果你有那么我怀疑你的问题,运行得更深一些: - )
Note that this will overcount if you have filenames with newlines embedded, but if you have that then I suspect your problems run a little deeper :-)
这篇关于庆典 - 什么是计算发现,效果最好的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!