Live data from Hacker News

Hacking ls -l

lemis.com

1–10 of 93 posts

Re: Hacking ls -l

#3
Or, you could use 'ls -h'...

(that said, I do see the utility, since it gives a more obvious visual queue as to the order of size differences... but if you're doing anything with the sizes programatically, you have to remove the commas afterwards... Short version: if you're going to do this, make it a unique flag, or a new flag modifier to the -l flag... don't overload the -l flag without recourse...)

Re: Hacking ls -l

#4
Is this front page worth materiel? I mean, it's good you took the time to add a ', but doing the same with sed would have been faster.

Alternatively, do you know about ls -lhrS? It will print size in human formats and reverse sort the files by size - ie the bigger will be at the end of the list

Re: Hacking ls -l

#5
post #2

While I appreciate the story, what's wrong with `ls -lh`?

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

#7
post #4

Is this front page worth materiel? I mean, it's good you took the time to add a ', but doing the same with sed would have been faster. Alternatively, do you know about ls -lhrS? It will print size in human formats and reverse sort the files by size - ie the bigger will be at the end of the list

Last sentence in the post says it all. Hacking is more than just coding and the steps he followed are illustrative in general.

Re: Hacking ls -l

#8
post #2

While I appreciate the story, what's wrong with `ls -lh`?

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.

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

#9
Guys! The point of this article is not to prescribe the only method of displaying human-readable file sizes. Obviously one could use `ls -lh`; the author clearly demonstrates that he is willing and able to read man pages to find answers.

Rather, this is a pretty interesting look into what it actually entails to make what ought to be a very simple and straightforward change.

It turns out that these simple changes are hard! Not just in identifying the piece of code to modify, but that man pages are often incomplete or unclear. It also illustrates the complexities behind making software portable - in this case, using the nation-neutral place separator. It also reminds us that solving what is on the surface a simple problem lets one uncover all sorts of interesting and messy details underneath - including more problems to solve!

These are steps that he'd have to take no matter what the code or feature. This article is not "complexity for complexity's sake", it's illustrating the complexity of making changes to any piece of code - and that it is surprisingly difficult for something that one would think is very easy!

Re: Hacking ls -l

#10

Earlier quoted context omitted.

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.

This works with sorting, and it's easier to pick big files out at a glance. I would use this as often as -h

`ls -lhS` works just fine to sort with human-readable sizes, at least on Fedora.
Post reply on HN