What is the best way to count “find” results?

前端 未结 4 1291
情歌与酒
情歌与酒 2020-11-27 04:07

My current solution would be find -exec printf \'.\' \\; | wc -c, but this takes far too long when there are more than 10000 results. Is there no f

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 04:23

    Why not

    find  | wc -l
    

    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.

提交回复
热议问题