How to sum the sizes of files found by ‘find’

Sometimes you want to find the size of all files that match some criteria, for example: files older than N days, or files greater than N bytes, or files that have a certain extension.

In this case, using du is not practical. Here is a simple awk one-liner that will sum the size of all files under /path that are older than 90 days:

find /path/ -type f -mtime +90 -printf "%s\n"|awk '{sum+=$0}END{print sum}'



Leave a Reply