Recursively counting files in a Linux directory

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

    If you want a breakdown of how many files are in each dir under your current dir:

    for i in */ .*/ ; do 
        echo -n $i": " ; 
        (find "$i" -type f | wc -l) ; 
    done
    

    That can go all on one line, of course. The parenthesis clarify whose output wc -l is supposed to be watching (find $i -type f in this case).

提交回复
热议问题