coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: null separated ls output option


From: Bernhard Voelker
Subject: Re: null separated ls output option
Date: Thu, 29 Jun 2017 08:31:48 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0

[adding findutils]
First of all, find(1) is maintained in the GNU findutils project,
not in GNU coreutils.

Redirected from:
  http://lists.gnu.org/archive/html/coreutils/2017-06/msg00049.html

On 06/28/2017 07:13 PM, Kaz Kylheku (Coreutils) wrote:
> On 28.06.2017 06:53, address@hidden wrote:
>> On 2017-06-01 04:45, Pádraig Brady wrote:
>>> On 31/05/17 15:24, address@hidden wrote:
>>> Existing tools like find(1) were thought sufficient
>>
>> but find does not support sorting by date which ls does.
>>
>> I hope this patch can be reconsidered for inclusion.
> 
> Rather than the obvious: patching find so that it supports sorting the 
> paths
> by date, or other properties?
> 
> This could be a "-sort <spec>" predicate, which is understood to be like
> "-print", except it sends the visited node into a sorting bucket, which
> is spilled when find finishes executing.  Sort buckets are identified by
> the "<spec>" syntax as a key, so multiple occurrences of the predicate
> giving the same <spec> go to the same bucket. Multiple occurrences of 
> -sort
> with different keys route to different buckets; these buckets can be
> later dumped in left to right order, based on the position of the
> leftmost predicate which specifies each bucket.
> 
> <spec> could use + and - as prefixes for ascending and descending 
> (defaulting
> to + if omitted) followed by a word which is derived from the space of 
> predicates:
> atime, ctime, name, iname, ...
> 
> Comma separation for compound keys? -sort mtime,name
> 
> Something like that.

I think the GNU toolbox already gives you enough flexibility to support
these edgy use cases, e.g. sorting by file size:

  find . -printf "%s/%p\0" \
    | sort -zt '/' -k1,1n  \
    | sed -z 's,^.*/,,'

The above find(1) prints the items separated by '\0', printing its
size %s and name %p separated by '/' - the only other character
apart from '\0' which can not occur in a file name.
Then, sort(1) sorts according to the first column.
Finally, sed strips off the file size and the decorating first slash.

The same works e.g. for mtime using the format string "%T@/%p\0", and
so on.

Given that sorting is not find(1) is supposed to do in the first
place, and that adding such feature would add a big amount of code
(which needs to be written and also maintained by someone), I think
the above alternative is sufficient.

Have a nice day,
Berny



reply via email to

[Prev in Thread] Current Thread [Next in Thread]