how to get figure out average file size

Pushrod

Well-Known Member

Reaction score: 21
Messages: 279

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

Does not read symlinks.
 

Djn

Well-Known Member

Reaction score: 67
Messages: 392

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

Well-Known Member

Reaction score: 21
Messages: 279

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.
 
Top