Recursively counting files in a Linux directory

后端 未结 21 1065
既然无缘
既然无缘 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:44

    If what you need is to count a specific file type recursively, you can do:

    find YOUR_PATH -name '*.html' -type f | wc -l 
    

    -l is just to display the number of lines in the output.

    If you need to exclude certain folders, use -not -path

    find . -not -path './node_modules/*' -name '*.js' -type f | wc -l
    

提交回复
热议问题