Sum the size of all files that match a pattern in a directory

A quick little command to print sum of the sizes of all files in a directory that match a pattern for a given date:

ls -ltr *.gz | grep "Nov 16" | awk '{sum = sum + $5} END {print ((sum/1024)/1024) " mb"}'

The sum of size all files in the current directory that have an extension of “.gz” and were created on “Nov 16” will be returned. The size, in mb, is a close approximation.

Author: Dean Capps

Database consultant at Amazon Web Services.