The order for
grep -r will generally be random (not necessarily alphabetical), typically based on how the files are arranged in the directory and what possible re-ordering your
grep implementation may do to optimise the directory traversal.
Here, with GNU
$ grep -r . .
If you want a specific order, you have to give up on
-r and give the list of files as arguments in the order you want.
For instance, in your case, and using
$ grep -H . ./**/*(D.On)
On for reverse order by name. You can add the
n qualifier for numeric sort:
$ grep -H . ./**/*(D.nOn)
-H being another GNU
grep extension to ensure the file name is always printed even if there's only one file. With other
grep implementation, you can add an extra empty file as argument like
/dev/null to make sure
grep is passed at least two file names).
That is also very useful to
zgrep rotated log files in chronological order (like
zgrep something access.log*(nOn)
(though you can also sort by last modification time with
zgrep something access.log*(Om) if those can be relied upon).