I'm attempting to write a shell command returning the most recently modified file.
However, the directory has more files than ls can accommodate directly (hence using find, which I understand to be the proper solution for piping into other commands anyway).
In doing so, I've encountered a confusing difference between running find . in the directory, and passing the directory to find (i.e. find $folder).
Here is an example:
➜ echo $SHELL
/usr/local/bin/zsh
➜ pwd
/Users/aresnick/Downloads
➜ find . -type f -maxdepth 1 -print0 | xargs -0 ls -t | head -1
./DID_Codebook_2020.pdf
➜ find $(pwd) -type f -maxdepth 1 -print0 | xargs -0 ls -t | head -1
/Users/aresnick/Downloads/Profiles17_MA.pdf
➜ find /Users/aresnick/Downloads -type f -maxdepth 1 -print0 | xargs -0 ls -t | head -1
/Users/aresnick/Downloads/Profiles17_MA.pdf
Note that DID_Codebook_2020.pdf is not the same file as Profiles17_MA.pdf. How can I explain why these commands seem to return different results?
For reference, here is the output of ls -halt | head -5 in the directory (including the two most recent files which are getting confused here).
➜ ls -halt | head -5
total 51229416
drwxr-xr-x+ 92 aresnick staff 2.9K Oct 12 10:34 ..
drwx------@ 4033 aresnick staff 126K Oct 12 10:02 .
-rw-r--r--@ 1 aresnick staff 1.7M Oct 12 10:02 DID_Codebook_2020.pdf
-rw-r--r--@ 1 aresnick staff 470K Oct 12 10:00 Profiles17_MA.pdf
Looking more closely via stat, it appears that the change time is in fact newer on Profiles17_MA.pdf:
➜ stat -f "ACCESS-%Sa CHANGE-%Sc %SN" {DID_Codebook_2020.pdf,Profiles17_MA.pdf}
ACCESS-Oct 12 10:02:14 2020 CHANGE-Oct 12 10:02:08 2020 DID_Codebook_2020.pdf
ACCESS-Oct 12 10:02:14 2020 CHANGE-Oct 12 10:02:10 2020 Profiles17_MA.pdf
However, I don't see how this explains why the sorting order would change with find . vs. find ~/Downloads.
What gives? I have the vague intuition that this may have something to do with the fact that we're looking at inodes' change times, and something about including the directory changes…something.
Thanks in advance! Note that while I am also interested in solutions to my specific sorting problem, I'm most interested in understanding why the difference occurs.