tech-misc archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

du -m is off



I noticed that a file of 10485760 bytes would be listed as 11MB by du -m. 
The -h "humanize" is correct and lists as 10MB.

du.c uses:

                (void)printf("%lld\t%s\n",
                    (long long)howmany(blocks, (int64_t)blocksize),

This works better for me:

printf("%ld\n", (long)((int64_t)blocks / blocksize));

But that doesn't help for files less than a megabyte which will then be 
displayed as a zero.

As another example, a file of 3372684 bytes is 3.21644MB. du -m would 
round up to 4. While my printf above prints "3".

I am not sure what correct behaviour should be.

Either way, the du man page should document about this as it is 
misleading.



Home | Main Index | Thread Index | Old Index