Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

As I see it ls does one job (list directory contents) and does it well (by supporting 37 flags).

If ls was a human, we would call him an expert.

Since unix tools expect input as plain text, the flags that ls supports are absolutely useful and I believe this is obvious to anyone who has written more than 50 lines of bash. When your input doesn't support a standard complex structure (e.g json with some standard set fields), claiming that “sort by creation time” is a simple filter is funny.

First you would need a ls flag so that ls will output creation times in an easy to process time format (seconds since epoch), then you would need to ask sort to work on a certain (1 flag) numerical (1 more flag) field. Last you would have to pass sort's output to a stream processor to get rid of unwanted fields.

Current “list files by creation time”:

    ls --sort=time --time=ctime
Replace sort flag with filters:

    ls -l --time=ctime --time-style="+%s" | sort -n -k 6 -r | awk '{ $1=$2=$3=$4=$5=$6=""; print substr($0,7) }'



The same in PowerShell - using ls without the abundance of parameters - would look like:

   ls | sort -des LastWriteTime | select name
1: Get the "child" items of the current directory 2: sort them descending according to the last write time 3: strip out all other properties but name

No need for ls to support a plethora of formatting options. And the typing is actually pretty short due to tab completion:

    ls | sort -des *time<tab><tab><tab><tab><tab> | select n<tab>
I could not remember what the "last change time" was called, so I just entered *time and used tab completion. PowerShell is smart enough to be aware that (one of) the output types from "ls" has a property called "LastWriteTime" - it came up after 5 tabs. Similarly when pressing n<tab> in the select it completed directly to Name because it knew (still from the pipeline) that output of "ls" would have a "Name" property - even if sorted first.


I totally agree that trying to filter the output of ls is madness when compared to using the built-in flags. But doesn't this also indicate that command output should be more unified in it's output format? "cut", for example, is a useful tool, but it seems ham-fisted as a way of formatting output data for anything other than a one-time job.


> As I see it ls does one job (list directory contents) and does it well (by supporting 37 flags).

That's exactly write. The author of the article seem to confuse "do one thing" with "implement one primitive function".

"List directory contents" is just one thing. How it's done is configurable, but it still does the same thing.


Nitpick, sorry. `ctime` is not Creation Time, but Change Time. The traditional *NIX file systems do not have a meta data field for creation time.


Thank you; I naively assumed since we have modification time (mtime), ctime would stand for creation time. :)




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: