Search code examples
bashfindfile-ownership

Summarize total size of files under ownership of a specific user


I want to sum up the size of all files (recursively) which are under the ownership of a specific user. Though, I don't want to have a huge list of all directories, just the overall size.

Therefore the solution from this answer like:

find . -user BobTheCat -type d -exec du -hs {} \;

has to be modified, but how?

I know it is possible with a post-treatment with something like awk but I guess this can be done more straightforward.


Solution

  • If your find ships with -printf, use that. E.g.:

    $ find . -user BobTheCat -type f -printf '%s\n' | awk '{bytes+=$0}END{print bytes}'