Page MenuHomeFreeBSD

ls -h: humanize the total as well
Needs RevisionPublic

Authored by pstef on Sun, Jan 5, 10:39 PM.
Tags
None
Referenced Files
F107116565: D48329.id148803.diff
Fri, Jan 10, 9:07 AM
F107116490: D48329.id148817.diff
Fri, Jan 10, 9:06 AM
F107112827: D48329.id.diff
Fri, Jan 10, 7:37 AM
F107110505: D48329.id148823.diff
Fri, Jan 10, 6:41 AM
F107099507: D48329.id148798.diff
Fri, Jan 10, 2:47 AM
F107096996: D48329.diff
Fri, Jan 10, 1:46 AM
F107086928: D48329.diff
Thu, Jan 9, 9:59 PM
Unknown Object (File)
Mon, Jan 6, 2:17 PM

Details

Summary

Before this change, the total printed on the first line was always in
blocks.

Now long format with -h will print both the "humanized number" and the
number of blocks.

ls -sh never provided sizes in anything other than blocks, total or
individual, and this commit doesn't change that.

The total number of blocks is a sum of fts_statp->st_blocks, so it's
multiplied by 512 and not by blocksize.

$ ls -lh /usr/bin | head -n 2
total 442 MB in 452226 blocks
-r-xr-xr-x 1 root wheel 70B Dec 20 21:06 CC

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

pstef requested review of this revision.Sun, Jan 5, 10:39 PM
pstef edited the summary of this revision. (Show Details)
ziaee requested changes to this revision.Wed, Jan 8, 3:05 AM
ziaee added a subscriber: ziaee.

Hi! This is a really interesting proposal! I always wished it did this, but also thought there was almost certainly some excellent reason why it hasn't. Since this is the foundation of userspace generations of scripts are built from, and thy Holy POLA of FreeBSD, I'm going to CC community leaders and grandmasters. Please forgive the disruption if this is undesirable. Thanks!

bin/ls/ls.1
505–506 ↗(On Diff #148823)

I'm not sure this should be done, but if we are going to do it. please integrate the documentation into the existing documentation like so.

544–546 ↗(On Diff #148823)

I think this looks tacked on. See above for my suggestion how to integrate it into the doc.

This revision now requires changes to proceed.Wed, Jan 8, 3:05 AM

Scripts shouldn't be using -h.

Scripts shouldn't be using -h.

(... unless what they do is pretty up something for the user, without actually understanding the bits they process.)

I think this change makes good sense, and it is arguably an oversight that it wasn't done that way when -l learned about -h

glebius added a subscriber: glebius.

I agree that scripts shouldn't use -h.

I agree with @phk that this was probably an oversight. I'm not sure I'd include blocks under -h -- why not just total 268503 without -h and total 131M with -h?

I agree with @phk that this was probably an oversight. I'm not sure I'd include blocks under -h -- why not just total 268503 without -h and total 131M with -h?

I wanted to keep the information that was always there, in case someone got used to it.

I wanted to keep the information that was always there, in case someone got used to it.

Just as a data point, GNU ls doesn't print the number of blocks with -h. Which doesn't mean it is bad to print it, especially given that scripts should not use -h. No personal preference here.

Just as a data point, GNU ls doesn't print the number of blocks with -h. Which doesn't mean it is bad to print it, especially given that scripts should not use -h. No personal preference here.

I know that it doesn't, but FreeBSD does and I assume it always did. I don't want to take away it, just add the "humanized" form.

It seems reasonable to me to switch to (rather than add) the humanized form for -h which is what's already done for the files in the list. "xMB in y blocks" also gives me the impression that we're presenting two different quantities (e.g. that 1M could be in some arbitrary number of blocks) - it would probably make more sense to show it as "total %s (%lu blocks)" if keeping both.

It seems reasonable to me to switch to (rather than add) the humanized form for -h which is what's already done for the files in the list. "xMB in y blocks" also gives me the impression that we're presenting two different quantities (e.g. that 1M could be in some arbitrary number of blocks) - it would probably make more sense to show it as "total %s (%lu blocks)" if keeping both.

My personal preference is only "x MB" as well, but my preference is unimportant here. I can do whichever of the 3 versions or something different still. Just waiting for some consensus.

I agree that -h changes the format of all numbers, So it should just be "x MB".

I vote for just outputting the size in bytes as a single value as well ("x MB")