[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [coreutils] "ls -lh" rounds up the size of files instead of rounding
Re: [coreutils] "ls -lh" rounds up the size of files instead of rounding half up/down.
Mon, 10 Jan 2011 13:43:35 -0700
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:220.127.116.11) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.7
On 01/10/2011 01:30 PM, crocket wrote:
> There is a file whose size is 42949837312bytes.
> It's almost exactly 40.000153064727783GB.
> "ls -lh" displays it as 41GB.
> It is resulted due to rounding up.
> However, rounding half down/up is much more common than rounding up in the
> When I expect moderate file size approximation, this 1GB difference is not
> Is there any reason for this behavior?
Yes. -h is a GNU extension, but the comparable -k and -s options have
behavior specified by POSIX. And POSIX requires that these options
round up to the next integral number of units. Therefore, it is as if
once you cross a unit boundary, ls is treating that unit as the block
size and rounding up to the effective number of blocks of that unit
size, since you've lost the fractional portion (that is, it's better to
overestimate than underestimate when it comes to disk usage).
under STDOUT: "If any of the -l, -n, -s, [XSI] [Option Start] -g, or -o
[Option End] options is specified, each list of files within the
directory shall be preceded by a status line indicating the number of
file system blocks occupied by files in the directory in 512-byte units
if the -k option is not specified, or 1024-byte units if the -k option
is specified, rounded up to the next integral number of units".
> Or is it just a mistake?
No, it is intentional.
Eric Blake address@hidden +1-801-349-2682
Libvirt virtualization library http://libvirt.org
Description: OpenPGP digital signature