1

I have a directory which contains sub-directories, which in turn contain sub-directories, which contain files. How can I list the number of files in each sub-directory recursively?

from this question I know that

du -a | cut -d/ -f2 | sort | uniq -c | sort -nr

will list the number of files on the current directory level. How can I do this recursively?

I have also seen this possibility, however I can't get it to work for my specific problem.

oguz ismail
  • 1
  • 16
  • 47
  • 69
Abdirizak
  • 80
  • 1
  • 7

1 Answers1

1

A conjunction of find and sh could easily do the trick. E.g.:

find . -type d -exec sh -c '
for d; do
  set -- "$d/"*
  printf "%d\t%s\n" $# "$d"
done' _ {} +
oguz ismail
  • 1
  • 16
  • 47
  • 69