# how to get figure out average file size



## graudeejs (Dec 27, 2008)

how to figure out average file size on fs?


----------



## Pushrod (Dec 27, 2008)

find /mydir -type f -print | perl -nle 'chomp; $s+=-s; END { print "AVG=".int($s/$.)}'

Does not read symlinks.


----------



## Djn (Dec 31, 2008)

Alternatively, use df to find the space used, and something to find the number of files (e.g. _find -x /mountpoint -type f | wc_), then divide it out. Not quite as elegant, but perhaps easier to remember.


----------



## Pushrod (Dec 31, 2008)

If you want to use df, you can do this:

df -bi /myfs | awk '{print $3*512/$6}'

Note that it is not as accurate because df won't show bytes used, only 512-blocks as a minimum. On a big filesystem with few files, it will be close enough for government work.


----------

