How to count number of files in each directory?

前端 未结 17 2718
小蘑菇
小蘑菇 2020-12-07 07:05

I am able to list all the directories by

find ./ -type d

I attempted to list the contents of each directory and count the number of files i

17条回答
  •  失恋的感觉
    2020-12-07 08:06

    This can also be done with looping over ls instead of find

    for f in */; do echo "$f -> $(ls $f | wc -l)"; done

    Explanation:

    for f in */; - loop over all directories

    do echo "$f -> - print out each directory name

    $(ls $f | wc -l) - call ls for this directory and count lines

提交回复
热议问题