Search code examples
filesystemscommand-line-interfacefilesizedu

Why does du -k display block counts in 4096-byte blocks even though it says 1024?


When I ran this

du -k *

I expected the output for each file to be ceil(filesize/1024) but the output was ceil(filesize/4096) * 4. Why is that?

Description of -k in $ man du: Display block counts in 1024-byte (1-Kbyte) blocks.

I'm using OS X if that makes any difference.


Solution

  • The file system allocates space in units of 4K (4096 bytes). If you create a 1 byte file, the file system will allocate 4K of storage to hold the file.

    The du -k command reports the total storage used by the file system. So du -k reports that the file system is using 4K of space for that file.