I own two macbook pros, purchased several years apart:
- BNW purchased 2015, currently running macOS Mojave 10.14.6
- kpr purchased 2019, currently running macOS Catalina 10.15.7.
The meaning of mtime and atime (modification time and access time for a file) seems to have changed between these two machines. The following code illustrates this. I used to be able to rely on atime to see if a file had recently been accessed. But with the newer machine, this no longer works.
First, the code by which I test this:
#!/bin/bash
whoami
/bin/rm z
touch z
stat -s z | perl -p -e 's/ +/n/g' | perl -n -e 'print if (/_[am]time/)'
sleep 10
cat z
stat -s z | perl -p -e 's/ +/n/g' | perl -n -e 'print if (/_[am]time/)'
Run it on BNW, and you see that the atime increased by 10 seconds, because it had been accessed by cat
, as expected:
> ./bashatimemtime
BNW
st_atime=1629320252
st_mtime=1629320252
st_atime=1629320262
st_mtime=1629320252
>
But on kpr, the atime remains identical to the mtime, in spite of cat
having accessed the file 10 seconds after its creation.
> ./bashatimemtime
kpr
st_atime=1629319817
st_mtime=1629319817
st_atime=1629319817
st_mtime=1629319817
>
What exactly is going on? Certainly this change must have been announced somewhere. Is there a url where this is explained?