There's two issues; how cd
behaves, which is easy to test via:
bash-4.1$ mkdir first second
bash-4.1$ cd first second
bash-4.1$ pwd
/home/jdoe/first
bash-4.1$
So cd
for this shell is going to the first item found. Second, find
itself may or may not be doing any sorting of the results, and for directories (probably) only has a -d
or "find first by depth" option, which would return /some/deeper/dir
before /some
or /
. Thus, you're left with what the system call returns, getdents(2)
from a quick strace
of find
on Linux. These entries should not ever be assumed to be sorted in a particular order (unless something like ls
sorts them for you):
bash-4.1$ mkdir c ; sleep 5
bash-4.1$ mkdir b ; sleep 5
bash-4.1$ mkdir a ; sleep 5
bash-4.1$ find .
.
./b
./c
./a
If in doubt, you'll need to enforce some sort of sorting on the results, as by default, find
will find whatever the underlying system call for the filesystem returns first.