4

I'm trying to find out the total size of all files owned by a given user.

I've tried this:

find $myfolder -user $myuser -type f -exec du -ch {} +

But this gives me an error:

missing argument to exec

and I don't know how to fix it. Can somebody can help me with this?

Mat
  • 202,337
  • 40
  • 393
  • 406
minh911
  • 51
  • 4

3 Answers3

2

You just need to terminate the -exec. If you want the totals for each directory possibly -type d is required.

find $myfolder -user $myuser -type d -exec du -ch {} \;
suspectus
  • 16,548
  • 8
  • 49
  • 57
  • `+` should work as well; it tells `find` to pass multiple arguments (up to some internal limit) thus reducing the number of subprocesses spawned. – Jim Garrison May 04 '13 at 21:28
1

Use:

find $myfolder -user gisi -type f -print0 | xargs -0 du -sh

where user gisi is my cat ;)

Note the option -s for summarize

Further note that I'm using find ... -print0 which on the one hand separates filenames by 0 bytes, which are one of the few characters which are not allowed in filenames, and on the other hand xargs -0 which uses the 0 byte as the delimiter. This makes sure that even exotic filenames won't be a problem.

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
0

some version of find command does not like "+" for termination of find command use "\;" instead of "+"