calculate total used disk space by files older than 180 days using find

du wouldn't summarize if you pass a list of files to it.

Instead, pipe the output to cut and let awk sum it up. So you can say:

find . -mtime +180 -exec du -ks {} \; | cut -f1 | awk '{total=total+$1}END{print total/1024}'

Note that the option -h to display the result in human-readable format has been replaced by -k which is equivalent to block size of 1K. The result is presented in MB (see total/1024 above).


@PeterT is right. Almost all these answers invoke a command (du) for each file, which is very resource intensive and slow and unnecessary. The simplest and fastest way is this:

find . -type f -mtime +356 -printf '%s\n' | awk '{total=total+$1}END{print total/1024}'

Why not this?

find /path/to/search/in -type f -mtime +180 -print0 | du -hc --files0-from - | tail -n 1