kyclark / command-line-rust

Code for Command-Line Rust (O'Reilly, 2024, ISBN 9781098109417)
https://learning.oreilly.com/library/view/command-line-rust/9781098109424/
MIT License
1.55k stars 252 forks source link

FWIW: `find` output differs from book (and appears to be expected) #22

Open atc0005 opened 4 months ago

atc0005 commented 4 months ago

TL; DR

The output differs system to system regardless of the find implementation (BSD vs GNU) that is used.

Overview

This is less of a bug report and more of a FYI for others going through the book. No matter the version of find that I tested with the output did not match what the book shows.

Version of repo used:

$ git log -n 1
commit 10d983f68e84b9c94057da6ecf555bc419e11999 (HEAD -> main, origin/main, origin/HEAD)
Author: Ken Youens-Clark <kyclark@gmail.com>
Date:   Tue Mar 19 11:35:02 2024 -0700

    readme

From the book

CH7, page 144-145 (epub) of the book notes that the BSD find output is on the left with GNU version on Linux on the right:

$ find .                          $ find .
.                                 .
./g.csv                           ./d
./a                               ./d/d.txt
./a/a.txt                         ./d/d.tsv
./a/b                             ./d/e
./a/b/b.csv                       ./d/e/e.mp3
./a/b/c                           ./d/b.csv
./a/b/c/c.mp3                     ./f
./f                               ./f/f.txt
./f/f.txt                         ./g.csv
./d                               ./a
./d/b.csv                         ./a/a.txt
./d/d.txt                         ./a/b
./d/d.tsv                         ./a/b/c
./d/e                             ./a/b/c/c.mp3
./d/e/e.mp3                       ./a/b/b.csv

Ubuntu 20.04 (WSLv2)

$ git clone https://github.com/kyclark/command-line-rust
$ cd command-line-rust/07_findr/tests/inputs
$ find .
.
./a
./a/a.txt
./a/b
./a/b/b.csv
./a/b/c
./a/b/c/c.mp3
./g.csv
./f
./f/f.txt
./d
./d/d.tsv
./d/d.txt
./d/e
./d/e/e.mp3
./d/b.csv

Ubuntu 22.04 (WSLv2)

$ git clone https://github.com/kyclark/command-line-rust
$ cd command-line-rust/07_findr/tests/inputs
$ find .
.
./g.csv
./d
./d/b.csv
./d/e
./d/e/e.mp3
./d/d.txt
./d/d.tsv
./f
./f/f.txt
./a
./a/a.txt
./a/b
./a/b/c
./a/b/c/c.mp3
./a/b/b.csv

FreeBSD 14

$ git clone https://github.com/kyclark/command-line-rust
$ cd command-line-rust/07_findr/tests/inputs
$ find .
.
./a
./a/a.txt
./a/b
./a/b/b.csv
./a/b/c
./a/b/c/c.mp3
./d
./d/b.csv
./d/d.tsv
./d/d.txt
./d/e
./d/e/e.mp3
./f
./f/f.txt
./g.csv

Thus far I've been using tools provided by a FreeBSD 14 VM as a reference for the BSD version of each tool covered by the book. Having a BSD version of the tools to contrast against the GNU version of the tools on an Ubuntu instance has been very helpful as I've gone through the exercises.

Explanation

Based on light research, the default find sort order appears to be based on the order items are stored within the directory entries. As noted in the serverfault.com Q/A below, the sort order should ordinarily be stable for the same machine but is subject to change if the filesystem entries are modified as part of maintenance operations.

References: