News for hackers. Stuff that matters.
Re:Unix doesn’t follow the Unix philosophy by udp on Friday May 25, 2012 @09:31AM (#4023357)
> Why does ls have dozens of tangled options? Because users, even Unix users, are not overly fond of the first two points of the Unix philosophy.

No, ls(1) is flexible because the philosophy is to do one thing and do it well.

ls(1) lists information about files. That's what `man ls` says it will do, and whichever flags you pass, that's what it's going to do. Providing a lot of control over how exactly it does that is (imho) doing it well.

Re:Unix doesn’t follow the Unix philosophy by telemachos on Friday May 25, 2012 @09:41AM (#4023392)
> No, ls has dozens of tangled options because the philosophy is to "do one thing and do it well".

Do you mean that in order to truly do well its one thing (list information about files), that ls had to incorporate things like these?

      -o      List in long format, but omit the group id.

      -T      When used with the -l (lowercase letter ``ell'') option, display complete
              time information for the file, including month, day, hour, minute, second,
              and year.

      -x      The same as -C, except that the multi-column output is produced with entries
              sorted across, rather than down, the columns.
Some degree of feature creep is probably inevitable, but a lot of the common utilities now seem to lean towards "offer a flag for everything" rather than "do a small number of permutations on one thing; create pipelines for the rest". (Note: These three options are all from OSX's BSD-derived ls. GNU's version is almost certainly more complex still.)
Re:Unix doesn’t follow the Unix philosophy by masklinn on Friday May 25, 2012 @10:02AM (#4023488)
> that ls had to incorporate things like these?

Or this bunch:

     -p      Write a slash (`/') after each filename if that file is a directory.

     -r      Reverse the order of the sort to get reverse lexicographical order or the oldest entries first (or largest files last, if combined with sort by size

     -S      Sort files by size
* -p's information is redundant with the first character of the long format

* -S (and -r) are redundant with `sort` (ls -lSr -> ls -l | sort -k5; ls -lS -> ls -l | sort -rk5)

Re:Unix doesn’t follow the Unix philosophy by lmm on Friday May 25, 2012 @10:21AM (#4023585)
-p is immensely useful. Of course it's redundant in long format; it's for using in short format.

-r is also very useful (I use -tr all the time, which I can't immediately see how I'd replace with sort), and while I could replace ls -lS with piping into sort, you seem to be assuming ls will always be outputting one file per line, which is far from its most useful output mode when running it in a terminal.

Re:Unix doesn’t follow the Unix philosophy by masklinn on Friday May 25, 2012 @10:38AM (#4023657)
> you seem to be assuming ls will always be outputting one file per line

No, I am assuming a "do one thing" `ls` would be used in long format (or as inode numbers) whenever it need to be worked with, and would be massaged into form by further commands. For `t`, `r`, `S` and a bunch of others you'd ls, sort and then cut/awk/whatever to format into a "short form".

Not that it matters a bit.

Also, I didn't claim these weren't useful, I claimed they were redundant. Which they are.

Re:Unix doesn’t follow the Unix philosophy by sp332 on Friday May 25, 2012 @10:18AM (#4023563)
-o is probably for compatibility with some other system. -T seems useful doesn't it? How else would you get that info? And -x is a personal preference. None of those seem especially useless.
Re:Unix doesn’t follow the Unix philosophy by telemachos on Friday May 25, 2012 @10:28AM (#4023621)
> -T seems useful doesn't it? How else would you get that info?

The long (-l) format already provides the month, day, hour and minutes. -T adds only seconds and the year. No utility can possibly provide every format option that someone might find useful. If you really needed that format, and ls were leaner, you would need to write a script (in whatever language).

> And -x is a personal preference.

Basic utilities shouldn't include so many options that are variants for personal preferences.

> None of those seem especially useless.

I don't think that they are outrageously useless, but let's set the bar higher. The core utilities should be, in my opinion, much much leaner than they are.

Re:Unix doesn’t follow the Unix philosophy by betawolf33 on Friday May 25, 2012 @09:40AM (#4023390)
In a sense, yes. However, some of the things ls does are 'borrowed functionality'. That the displayed listing can be sorted by a flag to ls is a bit of an aberration in the Unix philosophy. We're meant to have a separate tool for sorting - sort.

I agree that a certain flexibility is useful in the Unix tools, but a well-founded argument can be made that flexibility costs you simplicity.

Re:Unix doesn’t follow the Unix philosophy by pilif on Friday May 25, 2012 @09:48AM (#4023428)
The fact that ls can produce output that can't be reliably sorted using the sort utility shows that ls is actually doing three things instead of just one: Listing files, sorting the output and then displaying the output in a human readable format.

This is not to criticize ls though - I would imagine that no matter how small the operation (well aside of operations executed directly by the cpu), there's still the possibility to break it up into smaller parts.

At some point convenience just trumps modularity.

ls -lt is just more convenient than a (hypotetical) ls -t | sort | xargs fileinfo | display-fileinfo

On a related note: Windows PowerShell comes closer to this ideal by being able to send arbitrary objects between pipes. This still has the side-effect though that single commands become much more awkward to use as they don't produce output that's usable on its own.

Re:Unix doesn’t follow the Unix philosophy by cturner on Friday May 25, 2012 @09:58AM (#4023463)

    I would imagine that no matter how small the operation
    (well aside of operations executed directly by the cpu),
    there's still the possibility to break it up into smaller
    parts.
The scripting system could have been designed to make layering easier. Bourne descendants are ugly and awkward. Hence, unix evolved into a situation where ls had lots of features, whereas were there a better scripting system, we might have had a standard environment which you could introspect deeper and extend with more confidence.
Re:Unix doesn’t follow the Unix philosophy by ori_b on Friday May 25, 2012 @10:04AM (#4023494)
> The scripting system could have been designed to make layering easier.

How? sh sucks for anything involved, but I can't think of a way to simplify pipelines much.

Re:Unix doesn’t follow the Unix philosophy by jcmhn on Saturday May 26, 2012 @12:28AM (#4026485)
A line oriented xargs could have been built in from day one.

A pair of shell variables honored by commands that let you specify output wrappers or separators would have been nice too. Think "-Q" in gnu ls, but universally supported and user-controlled.

Re:Unix doesn’t follow the Unix philosophy by reddit_clone on Friday May 25, 2012 @10:21AM (#4023581)
How would you make 'sort' do all the things that 'ls' can easily do?

How do you sort a multi-column output by 3rd column?. You have to write some scripts for that.

Re:Unix doesn’t follow the Unix philosophy by elwin on Friday May 25, 2012 @10:41AM (#4023683)
sort -k 3
Re:Unix doesn’t follow the Unix philosophy by tedunangst on Friday May 25, 2012 @11:16AM (#4023822)
That 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?

Re:Unix doesn’t follow the Unix philosophy by betawolf33 on Friday May 25, 2012 @11:39AM (#4023930)
While 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.

Re:Unix doesn’t follow the Unix philosophy by masklinn on Friday May 25, 2012 @12:54PM (#4024352)
> 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.

Re:Unix doesn’t follow the Unix philosophy by tedunangst on Friday May 25, 2012 @02:18PM (#4024774)
Sure. 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.

Re:Unix doesn’t follow the Unix philosophy by reddit_clone on Friday May 25, 2012 @10:12AM (#4023532)
I agree.

It is not like 'ls' is predicting weather and telling the fortune.

It lists files and directories. It has a zillion options to control its behaviour and output. I see nothing wrong with those options if they will be of use to somebody. I use 4-5 options myself and know them by heart.

I do admit that a new user can get overwhelmed if he looks at the man page.

Re:Unix doesn’t follow the Unix philosophy by quesera on Friday May 25, 2012 @11:55AM (#4024005)
I agree. ls is primarily a user-facing utility, and has acquired a ton of display and formatting switches. This is not a bad thing. Some of the display options are superfluous but convenient. Others are awkward, very hard, or impossible to duplicate in a pipeline.

New users don't need to be overwhelmed by the man page. -a and -l should be enough for >99% of use cases.

ls shows up in shell scripts too, but that's almost always a mistake -- or a dependency on one of the harder-to-duplicate formatting options.