-1

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
ABCDEF

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

and

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
0000007
BaRud
  • 1,639
  • 2
  • 17
  • 26
  • What is your sector size? My SSD is 512 but large hard drives use 4k. sudo fdisk -lu https://developer.ibm.com/tutorials/l-4kb-sector-disks/ – oldfred Dec 20 '22 at 19:44