Search code examples
linuxterminalstat

How stat show a file size?


just curios how stat show a file size.... for example I have a file with only one letter in it

echo a > test

when I do

 stat test 

I see Size: 2

but when I do

 du -h test

I see 4.0K

So what I'm missing ? Thanks


Solution

  • As per the du(1) manpage, du estimates disk usage, it doesn't show apparent file size, unless you pass --apparent-size.

    It seems the estimation is based on the assumption of a 4096-byte disk allocation granularity. (Make a 4097-bytes-large file, du will report 8KiB, etc.).