[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#33577: ls lacks null terminator option
From: |
Bernhard Voelker |
Subject: |
bug#33577: ls lacks null terminator option |
Date: |
Wed, 5 Dec 2018 11:25:29 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 |
On 12/4/18 9:35 PM, 積丹尼 Dan Jacobson wrote:
> Bob, I remember from my K&R Unix book that ls can be used in scripts.
> In fact that is why
> $ ls
> acts different than
> $ ls | cat
>
> Plus there are lots of things ls can do that find cannot.
>
> For instance sorting.
You didn't mention sorting in your original post, but actually that's a
typical post-action which can be glued together the UNIX way via pipes,
using the decorate-process-undecorate pattern:
$ find -printf '%T@:%p\0' | sort -znr | cut -zd: -f2- | $PRG
with e.g.
PRG='head -zn1'
to get the newest file.
And yes, if you really want to cater for arbitrary file names with blanks,
newlines, and control character - short: everything apart from '/' and '\0',
or more malicious file names e.g. starting with '-' or '--' to fool scripts,
then it is quite complex by nature to get it right: think about what
you have to do in the consuming $PRG to perform the processing safely.
> Are you saying you want to enhance find(1) to sort its output?
No, because that what 'sort' is for.
Have a nice day,
Berny