0

In Linux, I know I can use

find ./ -size +1M

to find files which are bigger than 1M, but how do I sum the total space needed by these files?

2

You can -execute a program on each of the find results.

-exec utility [argument ...] {} +

Same as -exec, except that ```{}''is replaced with as many pathnames as possible for each invocation of utility. This behaviour is similar to that ofxargs(1)`.

Run du -c to sum of disk usage (number of used blocks) on the results, like this:

find ./ -size +1M -exec du -c {} +

Optionally add -h to get human readable sizes, or -k for 1k blocks. Add -s if a different find expression also returns folders.

This requires that there aren't too many results, since it builds a single du call from the file names, and if that gets too long, it'll split it up into separate calls with separate totals.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.