计算“发现"数量的最佳方法是什么?结果? [英] What is the best way to count "find" results?
本文介绍了计算“发现"数量的最佳方法是什么?结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我当前的解决方案是find <expr> -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?
推荐答案
请改用此方法(需要find
的-printf
支持):
Try this instead (require find
's -printf
support):
find <expr> -type f -printf '.' | wc -c
比计数行数更可靠,更快.
It will be more reliable and faster than counting the lines.
请注意,我使用的是find
的printf
,而不是外部命令.
Note that I use the find
's printf
, not an external command.
让我们坐下吧:
$ ls -1
a
e
l
ll.sh
r
t
y
z
我的代码段基准:
$ time find -type f -printf '.' | wc -c
8
real 0m0.004s
user 0m0.000s
sys 0m0.007s
用实线表示:
$ time find -type f | wc -l
8
real 0m0.006s
user 0m0.003s
sys 0m0.000s
所以我的解决方案更快=)(重要的部分是real
行)
So my solution is faster =) (the important part is the real
line)
这篇关于计算“发现"数量的最佳方法是什么?结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文