On my linux system if I display the current date "t1", touch a file "f" then display the modification time "t2" of that "f" I would expect t1 < t2.
But that's not what I always get when I execute this on my system:
date +'%Y-%m-%d %H:%M:%S.%N'; \
touch f; \
stat -c %y f
Example output:
2017-09-18 21:47:48.855229801
2017-09-18 21:47:48.853831698 +0200
Notice the second timestamp (stat) is before the first one (date): 855229801 > 853831698
My fs is ext4, but I also tried with a file on tmpfs, same effect.
Why is it the case?
Thanks
Some info about the setup
% which date
/usr/bin/date
% which touch
/usr/bin/touch
% pacman -Qo /usr/bin/date /usr/bin/touch
/usr/bin/date is owned by coreutils 8.28-1
/usr/bin/touch is owned by coreutils 8.28-1
% uname -a
Linux machine 4.12.12-1-ARCH #1 SMP PREEMPT Sun Sep 10 09:41:14 CEST 2017 x86_64 GNU/Linux
% findmnt
TARGET SOURCE FSTYPE OPTIONS
/ /dev/sda1 ext4 rw,relatime,data=ordered
└─/tmp tmpfs tmpfs rw,nosuid,nodev
Best Answer
Per https://stackoverflow.com/questions/14392975/timestamp-accuracy-on-ext4-sub-millsecond :