|
1 | 1 | # Extensions |
2 | 2 |
|
3 | | -TODO |
| 3 | +The goal of this project is to be a drop-in replacement for GNU findutils, so by |
| 4 | +default the tools behave exactly like the originals. A few opt-in extras go |
| 5 | +beyond what GNU offers; they are all off unless you ask for them, and none of |
| 6 | +them change the default output. |
| 7 | + |
| 8 | +The sections below are the only ones. Nothing else here is an addition to GNU: |
| 9 | +every other predicate, option, `-printf` directive and environment variable |
| 10 | +either matches GNU or is still missing. In particular `LOCATE_PATH`, |
| 11 | +`FINDOPTIONS`, `PRUNEPATHS`, `PRUNEFS`, `NETPATHS`, `LOCALUSER` and `NETUSER` |
| 12 | +are standard findutils variables, not extensions. Where we differ from GNU it is |
| 13 | +a gap rather than an extra — see [GNU test coverage](test_coverage.md). |
| 14 | + |
| 15 | +## `-sorted`: deterministic traversal order |
| 16 | + |
| 17 | +GNU `find` returns entries in whatever order the filesystem hands them back, so |
| 18 | +two runs over the same tree can print the same lines in a different order. The |
| 19 | +`-sorted` predicate makes `find` sort each directory's entries by name before |
| 20 | +descending: |
| 21 | + |
| 22 | +```console |
| 23 | +$ find /srv/data -type f -printf '%f\n' |
| 24 | +yankee |
| 25 | +bravo |
| 26 | +mike |
| 27 | +alpha |
| 28 | +zeta |
| 29 | + |
| 30 | +$ find /srv/data -sorted -type f -printf '%f\n' |
| 31 | +alpha |
| 32 | +bravo |
| 33 | +mike |
| 34 | +yankee |
| 35 | +zeta |
| 36 | +``` |
| 37 | + |
| 38 | +It is a global flag rather than a test: it always matches, and it affects the |
| 39 | +whole traversal no matter where it appears in the expression. Sorting requires |
| 40 | +reading each directory in full before descending into it, so it costs memory and |
| 41 | +latency on very large directories — that is why it is opt-in rather than the |
| 42 | +default. |
| 43 | + |
| 44 | +This is most useful when you want reproducible output: comparing two trees, |
| 45 | +generating a manifest, or writing a test whose expected output is a fixed list |
| 46 | +of lines. |
0 commit comments