Any command to view the file system internal fragmentation size under a directory?

If the block size of a file system is 4KB, then for a 1KB file, 3KB space(which is internal fragmentation) is wasted. So, under a directory, is there any command to summarize how much disk space is wasted due to internal fragmentation?

Asked By: twimo


Except if you have sparse files, it sounds like you’re looking for du -s «dir» vs. du -s --apparent-size «dir».

Or, in stat output, the difference between size and blocks × block size:

anthony@Zia:/tmp$ echo -n 1 > foo 
anthony@Zia:/tmp$ stat -c '%s    %b × %B' foo 
1    8 × 512

And with du (which defaults to kilobytes, add -B 1 if you want bytes):

anthony@Zia:/tmp$ du foo 
4       foo
anthony@Zia:/tmp$ du --apparent-size foo 
1       foo

du will of course count entire directory trees, not just individual files.

Answered By: derobert
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.