Recursively counting files in a Linux directory

后端 未结 21 1071
既然无缘
既然无缘 2020-11-28 17:17

How can I recursively count files in a Linux directory?

I found this:

find DIR_NAME -type f ¦ wc -l

But when I run this it returns

21条回答
  •  时光取名叫无心
    2020-11-28 17:49

    Since filenames in UNIX may contain newlines (yes, newlines), wc -l might count too many files. I would print a dot for every file and then count the dots:

    find DIR_NAME -type f -printf "." | wc -c
    

提交回复
热议问题