计算“找到"的最佳方法是什么?结果? [英] What is the best way to count "find" results?

查看:14
本文介绍了计算“找到"的最佳方法是什么?结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的解决方案是 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.

请注意,我使用的是 findprintf,而不是外部命令.

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

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