Recursively counting files in a Linux directory

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

    If you want to know how many files and sub-directories exist from the present working directory you can use this one-liner

    find . -maxdepth 1 -type d -print0 | xargs -0 -I {} sh -c 'echo -e $(find {} | wc -l) {}' | sort -n
    

    This will work in GNU flavour, and just omit the -e from the echo command for BSD linux (e.g. OSX).

提交回复
热议问题