News for hackers. Stuff that matters.
Re:Hacking ls -l by cheald on Saturday October 13, 2012 @04:15PM (#4649554)
While I appreciate the story, what's wrong with `ls -lh`?
Re:Hacking ls -l by paddyoloughlin on Saturday October 13, 2012 @06:44PM (#4649990)
For me, -h makes it more difficult to quickly compare the sizes of files in one list by glance. This is something that I have to do often enough that it has prevented me from adding -h to my ls alias. I'd have to use it for a bit to be sure, but the post's suggestion seems a pretty good 'best of both worlds' solution to me.
Re:Hacking ls -l by dredmorbius on Saturday October 13, 2012 @10:19PM (#4650384)
This.

I run into the situation more often with 'du' (when trying to find which subdirectory tree has excess junk in it), to the point that, while 'du -h' is human readable, it's not particularly sortable so:

    du -hs $( du -s * | sort -k1nr,1 -k2 | head )
.... which will return the human-readable output, based on numerically sorting the full numeric output. Eyeball comparisons are easier as you're aware that results are already sorted by size.
Re:Hacking ls -l by pwg on Saturday October 13, 2012 @11:11PM (#4650475)
A reasonably recent sort from GNU coreutils has a -h (and equivalent long option --human-numeric-sort) which properly sorts the output of du -h, meaning you can do:

du -h | sort -h

And get properly size-sorted output.

Re:Hacking ls -l by dredmorbius on Monday October 15, 2012 @02:26PM (#4656398)
TIL! Thanks.
Re:Hacking ls -l by pepve on Saturday October 13, 2012 @06:12PM (#4649904)
I guess people can be very different in this respect. I really need the full number (or at least all of the numbers in the same unit) to be displayed. I don't find the 'human' format helpful at all when looking at ls output.
Re:Hacking ls -l by sliverstorm on Saturday October 13, 2012 @10:33PM (#4650410)
It just depends what info you desire. I typically use "ls -lh" to quickly find large files to clean up to recover disk space.
Re:Hacking ls -l by tsahyt on Sunday October 14, 2012 @12:33PM (#4651765)
I use "du <directory> -h -d 1|sort -h" for this because large files may be nested in directories and ls doesn't display the size of content directories (as far as I know). The output is sorted. Note that the "-d" flag for "du" doesn't work with all versions, but there were similar flags on all systems.
Re:Hacking ls -l by sliverstorm on Monday October 15, 2012 @01:39AM (#4653923)
I don't usually have access to a version of "sort" that supports the "-h" flag.
Re:Hacking ls -l by ghostfish on Saturday October 13, 2012 @04:36PM (#4649606)
My thoughts exactly. This is just complexity for complexity's sake. Useful as an exercise, but the -h flag already does this is an even more readable manner.
Re:Hacking ls -l by bajsejohannes on Saturday October 13, 2012 @04:57PM (#4649675)
This works with sorting, and it's easier to pick big files out at a glance. I would use this as often as -h
Re:Hacking ls -l by cheald on Saturday October 13, 2012 @05:10PM (#4649719)
`ls -lhS` works just fine to sort with human-readable sizes, at least on Fedora.
Re:Hacking ls -l by runejuhl on Saturday October 13, 2012 @08:29PM (#4650212)
You could also use 'ls -lh | sort -h'.
Re:Hacking ls -l by sliverstorm on Saturday October 13, 2012 @10:32PM (#4650409)
I believe that's only supported in newer versions of sort.