Unix find average file size Unix find average file size unix unix

Unix find average file size


I found something here:
http://vivekjain10.blogspot.com/2008/02/average-file-size-within-directory.html

To calculate the average file size within a directory on a Linux system, following command can be used:

ls -l | gawk '{sum += $5; n++;} END {print sum/n;}'


A short, general and recursion-friendly variation of Ernstsson's answer:

find ./ -ls | awk '{sum += $7; n++;} END {print sum/n;}'

Or, for example, if you want to impede files above 100 KB from stewing the average:

find ./ -size -100000c -ls | awk '{sum += $7; n++;} END {print sum/n;}'


Use wc -c * to get the size of all the files and ls | wc -l to get the number of files. Then just divide one by the other.