4 ms·
sort -k 3
by elwin 14y ago
sort -k 3
- tedunangst 14y agoThat works for the trivial case of the 3rd column, but not for everything ls can produce. There's no way to make sort work on dates as formatted by ls (which may or may not have years or hours, depending on how old) or sizes (which you may want to pretty print as human readable.) What sort option puts 1.0K, 1.0M, and 1.0G in the right order?
- betawolf33 14y agoWhile I do appreciate the point that ls is doing sorting that sort would struggle to manage, isn't this an argument for better functionality in sort? Someone pointed out that ls is really doing three things - listing files, sorting them and displaying them. That seems fairly accurate, and indeed it's convenient that it does. But it's not 'doing one thing'. I'm not saying that's necessarily bad (as I just said, it's convenient), but it's not hardline Unix-way purity. For practical reasons like those you raise, it makes sense for ls to handle its own sorting rather than leave it to the sort command, just as it handles its own formatting rather than let the user manage it. But those features _are_ something other than just reporting file listings, whatever the motivation for the feature creep. This convenient flexibility makes ls less single-task, less Unix-adherent but more generally useful on its own.
- masklinn 14y ago> There's no way to make sort work on dates as formatted by ls (which may or may not have years or hours, depending on how old) or sizes (which you may want to pretty print as human readable.) Both of which wouldn't be the job of a "do one thing and do it well" `ls`. That one would display dates as a UNIX timestamp and sizes as bytes. Aside from that, surely if ls can format information it's possible to reverse that formatting.
- tedunangst 14y agoSure. Instead of running ls -lhrT, I could run ls -l | sort -n -r -k 5 | prettydate -k 6 | prettysize -k 5. Maybe make a shell alias. But at some point, I don't want my day to day life to be one big puzzle solving mission, I just want to get shit done. Is unix going to ship with 900 prettyX scripts, or do we make everybody write their own awk script? Here's another thought I had about the old school unix way. Old school unix didn't have symlinks. The purpose of the filesystem is to store files, right? If you want aliases, then you should keep them in a file like /etc/symlinks. Or ~/.symlinks, then every user can have their own aliases. That's the real unix way, right? Let's not take the minimalism to absurd extremes.