Manolo Díaz wrote:
> I find du buggy. I think it's taking International System of Units
> values as if they was binary values. An example:
>
> # stat file.pdf
> File: 'file.pdf'
> Size: 160594 Blocks: 320 IO Block: 4096 regular file
^^^ 320 (512 byte) blocks
I couldn't tell so I will assume a 512 byte block file system here.
> # ls -l file.pdf
> -r-------- 1 root root 160594 Dec 6 11:59 file.pdf
Not relevant. ls -l is reporting the file file but du reports the
amount of disk used. Those are two different things.
> # LC_ALL=C du file.pdf
> 160 file.pdf
du is reporting 160 (1024 byte) blocks used. It arrives at this by
usin gthe 320 (512 byte blocks) * 512 / 1024 = 160 (1024 byte) blocks.
> # du --si file.pdf
> 164k file.pdf
The --si option requests reporting disk usage in SI units of 1000. In
this case 320 (512 byte) blocks * 512 bytes per block = 163840 bytes
of disk usage. 163840 / 1000 = 164 and is reported as such.
> That is, I think it takes 160 kB as if it were 160 KiB.
I don't know where you are reading 160 kB from in any of the above. I
see only "160" when the default output is used. In that case the
units are blocks of 1024 bytes as documented.
The du documentation says:
With no arguments, ‘du’ reports the disk space for the current
directory. Normally the disk space is printed in units of 1024 bytes,
but this can be overridden (*note Block size::). Non-integer quantities
are rounded up to the next higher unit.
...
‘--si’
Append an SI-style abbreviation to each size, such as ‘M’ for
megabytes. Powers of 1000 are used, not 1024; ‘M’ stands for
1,000,000 bytes. This option is equivalent to ‘--block-size=si’.
Use the ‘-h’ or ‘--human-readable’ option if you prefer powers of
1024.
Therefore du is behaving as it should and as documented.
Note that du output may show different values for exactly the same
file when stored on different file systems due to the block and frag
sizes of the file systems being different. Since du shows the amount
of disk used the amount of disk used depends upon the file system upon
which the file is stored. This is sometimes something that confuses
people so I thought I would mention it.
Historical notes: The old System V and BSD du commands had different
output formats. The GNU flavor of du followed the BSD output style
since that was seen as the more user friendly format. The GNU version
differed from the traditional du by reporting disk used in the more
convenient sizes of 1024 instead of the original 512 byte block sizes.
The original du reported in disk blocks, which were 512 bytes in size,
and mental arithmetic was always needed. With GNU du the sizes were
in the convenient binary power of two sizes based upon 1024 byte
blocks. It has been so many years now that GNU du output itself is
historical and itself should not change or it would break many other
programs which rely upon its output not changing. (These days if you
want a particular non-default base for the block size one should
specify it explicitly.)
Bob