findutils-patches
[Top][All Lists]
Advanced

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

Add sort option to find


From: Diego Ongaro
Subject: Add sort option to find
Date: Tue, 18 Aug 2020 17:48:31 -0700

Hi,

Long time user, first time GNU contributor (I think). I'm submitting patches
to add a sort option to find. It will cause find to sort files by name within
each directory before processing them.

As I wrote in the info page, "the -s option is more efficient than piping
large amounts of output of find into the sort command, and it produces output
incrementally rather than buffering it all. It's also more convenient when
the output of a find command isn't line-oriented or the lines don't start
with the filenames."

This is not a new idea. It's been in this project's TODO file in the context
of updatedb since the year 2000. FreeBSD has included the -s flag in its man
page for find since FreeBSD 3.1 [1], which was released in 1999. Mac OS X
picked it up from FreeBSD.

Sorting has also been proposed previously on this mailing list. Phil Miller
submitted a patch in 2014 that used `-sort` as a predicate [2][3]. After some
discussion about sorting directories by inode, Phil's proposal appears to
have fallen through.

My proposal uses `-s` as a global option instead of Phil's `-sort` predicate.
The advantages of `-s` are (a) compatibility with BSD and Mac OS X and
(b) allowing users to easily create a shell alias for `find -s`.

One thing I didn't do is update the `oldfind` command to respect `-s`. It
looked like that would require a non-trivial change. Is `oldfind` still used?

Another thing is I didn't do is update the `updatedb.sh` script to take
advantage of `find -s`. I wanted to see if this change would be accepted
first. I also wasn't sure if testing for `find -s` should happen at
build-time (like `sort -z`) or at run-time.

Please see the attached patches:

    [PATCH 1/3] Add find -s (sort) global option
    [PATCH 2/3] find: Update docs for -s (sort)
    [PATCH 3/3] find: Add test for sort

I'll reply to this email with the patches too, and hopefully one of those
options will be readable to you all. Apologies in advance if I and/or GMail
mess that up.

Thanks for your feedback,
Diego

[1] https://www.freebsd.org/cgi/man.cgi?query=find&manpath=FreeBSD+3.1-RELEASE
[2] https://lists.gnu.org/archive/html/findutils-patches/2014-12/msg00005.html
[3] https://lists.gnu.org/archive/html/findutils-patches/2015-01/msg00003.html

Attachment: 0002-find-Update-docs-for-s-sort.patch
Description: Text Data

Attachment: 0001-Add-find-s-sort-global-option.patch
Description: Text Data

Attachment: 0003-find-Add-test-for-sort.patch
Description: Text Data


reply via email to

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