0

I'm making a 500MiB binary file like this:

$: dd if=/dev/zero of=mlinux.img bs=1048576 count=500

Then when I do:

$: du -b mlinux.img

It returns exactly 524288000

But when I do:

$: du -BMiB mlinux.img

It returns 501MiB

Why not exactly 500MiB ?

Bey Réda
  • 57
  • 5
  • Disk usage != file size. See `--apparent-size` of `du`. – dimich Oct 07 '22 at 09:55
  • If I try bs=1M count=500, I get exactly 500MiB – Bey Réda Oct 07 '22 at 10:02
  • 500MiB with `du`? I have `501` anyway. Both files are 524288000 bytes in size and use 1024008 blocks (check with `stat`) – dimich Oct 07 '22 at 10:09
  • I tried on another machine : dd if=/dev/zero of=mlinux.img bs=$((2**20)) count=500. Then du -BMiB (coreutils V 8.32) returns exactly 500MiB. So I'm a bit confused... – Bey Réda Oct 09 '22 at 08:27
  • By default `du` returns number of blocks allocated in filesystem, not file size. The same file may require different number of blocks in different circumstances. Check your file with `stat -c "size: %s, blocks: %b, block size: %B" mlinux.img`. Multiply number of blocks by block size and divide it by 1048576 with rounding up. This is how `du -BMiB` works. – dimich Oct 09 '22 at 10:20

0 Answers0