Com o FreeBSD / Mac OS X find
, stat
e awk
(não é exatamente uma descrição prática):
find -x . -type f -maxdepth 1 -exec sh -c 'stat -f '%z' "${@}"' _ '{}' + |
LC_ALL=C awk -v pwd="${PWD}" '
BEGIN{ sum=0; count=0; }
{ sum+=$1; ++count; }
END{
if (count == 0) exit;
printf ("number of files: %d\n", count);
printf ("average file size in B: %.5f\n", sum/count);
printf ("average file size in KB: %.5f\n", (sum/count) / 1024);
printf ("average file size in MB: %.5f\n", (sum/count) / (1024*1024));
printf ("directory: %s\n", pwd);
}
'