[BASH] Size of Multiple Directories

Hello all,

I am trying to print the sizes of all directories with the name target. I assumed I could do this:

find -maxdepth 3 -name target -type d | du -sh

However, this causes du to start listing the sizes of all directories. Am I incorrectly piping this?

I am still not sure why it does not work to pipe to du, but what works is to use -exec:

find -maxdepth 3 -name target -type d -exec du -sh '{}' \;

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.