I have an ASCII text file:

file foo
foo: ASCII text

which contains just 6 letters (I don't have any linebreak or space after "F"):

cat foo

since this is ASCII, the file size should simply be 6 byte (as ASCII is 1 byte per character).

But, if I use du to this, I am getting some confusing result:

du -bsch foo
7   foo
7   total


du -ksch foo
4.0K    foo
4.0K    total

So, not only the file size is higher than expected 6b, it is different when I write in the byte unit and in the kb unit.

So, my question is

  1. why the file size is higher than the expected 6b? Where the extra byte is going?
  2. Why the output of du is different in the different units?

NB: this is possibly not a Linux question. I put it here, instead of in some computer science forum, because I am using the Unix commands.

Update Sector Size:

Disk /dev/sda: 476.94 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: SanDisk SD8SN8U5
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: D12CA635-6354-48FF-A0D6-0D3CB4BDBE2E

Device         Start        End   Sectors   Size Type
/dev/sda1       2048     534527    532480   260M EFI System
/dev/sda2     534528     567295     32768    16M Microsoft reserved
/dev/sda3     567296  208748856 208181561  99.3G Microsoft basic data
/dev/sda4  208750592  210485247   1734656   847M Windows recovery environment
/dev/sda5  210485248  212582399   2097152     1G Linux filesystem
/dev/sda6  212582400 1000214527 787632128 375.6G Linux filesystem

Disk /dev/zram0: 7.65 GiB, 8210350080 bytes, 2004480 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Update od output:

od -c foo
0000000   A   B   C   D   E   F  \n

1 Answer 1


the modern file system in linux always has block size of 4096 bytes. You can use stat -f foo to verify that.

du -b tell you the apparent size with block-size=1. Thus it tell you the actual content bytes (also it does not aware of sparseness).

du -k give you the actual on disk size in KiB. You file is smaller than 4096 thus it give you 4k.

Here is an example:

du -b foo.txt 
4       foo.txt
du --block-size=1 foo.txt 
4096    foo.txt
du -b foo-5k.bin
5120    foo-5k.bin
du --block-size=1 foo-5k.bin
8192    foo-5k.bin

you can see the actual on-disk size is N*4096

Not the answer you're looking for? Browse other questions tagged .