If the mtimes of two files differ by less than 1 second while the component of secs in the same in both timestamps, the command "[ file1 -nt/-ot file2 ]" gives a wrong result. Here '[' is the bash builtin. Version-Release number of selected component (if applicable): bash-4.3.43-4.fc25.x86_64 bash-4.2.46-20.el7_2.x86_64 (RHEL 7.3) Steps to Reproduce: $ while true; do touch a; sleep 0.6; touch b; stat a b|grep Modify; [ b -nt a ] && echo test_cmd_ok; echo; done Actual results: Modify: 2017-06-01 19:31:05.699921567 +0200 Modify: 2017-06-01 19:31:06.303918131 +0200 test_cmd_ok Modify: 2017-06-01 19:31:06.309918097 +0200 Modify: 2017-06-01 19:31:06.913914657 +0200 Modify: 2017-06-01 19:31:06.918914629 +0200 Modify: 2017-06-01 19:31:07.522911187 +0200 test_cmd_ok Modify: 2017-06-01 19:31:07.527911159 +0200 Modify: 2017-06-01 19:31:08.132907713 +0200 test_cmd_ok Modify: 2017-06-01 19:31:08.137907685 +0200 Modify: 2017-06-01 19:31:08.742904235 +0200 Modify: 2017-06-01 19:31:08.748904201 +0200 Modify: 2017-06-01 19:31:09.351900765 +0200 test_cmd_ok Modify: 2017-06-01 19:31:09.357900731 +0200 Modify: 2017-06-01 19:31:09.961897294 +0200 Modify: 2017-06-01 19:31:09.967897260 +0200 Modify: 2017-06-01 19:31:10.570893817 +0200 test_cmd_ok Modify: 2017-06-01 19:31:10.576893783 +0200 Modify: 2017-06-01 19:31:11.180890345 +0200 test_cmd_ok Modify: 2017-06-01 19:31:11.186890311 +0200 Modify: 2017-06-01 19:31:11.789886880 +0200 Modify: 2017-06-01 19:31:11.795886846 +0200 Modify: 2017-06-01 19:31:12.399883404 +0200 test_cmd_ok Expected results: Modify: 2017-06-01 19:31:05.699921567 +0200 Modify: 2017-06-01 19:31:06.303918131 +0200 test_cmd_ok Modify: 2017-06-01 19:31:06.309918097 +0200 Modify: 2017-06-01 19:31:06.913914657 +0200 test_cmd_ok Modify: 2017-06-01 19:31:06.918914629 +0200 Modify: 2017-06-01 19:31:07.522911187 +0200 test_cmd_ok Modify: 2017-06-01 19:31:07.527911159 +0200 Modify: 2017-06-01 19:31:08.132907713 +0200 test_cmd_ok Modify: 2017-06-01 19:31:08.137907685 +0200 Modify: 2017-06-01 19:31:08.742904235 +0200 test_cmd_ok Modify: 2017-06-01 19:31:08.748904201 +0200 Modify: 2017-06-01 19:31:09.351900765 +0200 test_cmd_ok Modify: 2017-06-01 19:31:09.357900731 +0200 Modify: 2017-06-01 19:31:09.961897294 +0200 test_cmd_ok Modify: 2017-06-01 19:31:09.967897260 +0200 Modify: 2017-06-01 19:31:10.570893817 +0200 test_cmd_ok Modify: 2017-06-01 19:31:10.576893783 +0200 Modify: 2017-06-01 19:31:11.180890345 +0200 test_cmd_ok Modify: 2017-06-01 19:31:11.186890311 +0200 Modify: 2017-06-01 19:31:11.789886880 +0200 test_cmd_ok Modify: 2017-06-01 19:31:11.795886846 +0200 Modify: 2017-06-01 19:31:12.399883404 +0200 test_cmd_ok Additional info: Note that the '[' command from coreutils works as expected. A quick recursive grep of the filesystem reveals a certain number of instances of "[ -nt/-ot" in files belonging to some common packages like elfutils, git, grub as well as sendmail and postfix (at least in RHEL). I came accross this bug while debugging weird behavior of /etc/mail/make (part of sendmail, called e.g. from its systemd unit file) which wouldn't refresh the main config file sometimes if called in fast repetition. As far as RHEL is concerned, this issue might be of interest to the developers of packages that call "[ -nt/-ot". I'm at least adding CC: sendmail/posftix's Jaroslav Skarvada.
Thank you for reporting the bug! This seems to be caused by the get_stat_mtime_ns() function returning 0 because of STAT_TIMESPEC and STAT_TIMESPEC_NS not being defined. The autoconf tests check for sub-second precision for atime only, so we end up with HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC not being defined. But it doe not mean that we cannot obtain mtime with sub-second precision. In fact, strace shows that bash gets precise enough data but, if I stop gdb in timespec_cmp(), the tv_nsec fields are always zero. Note that this bug is specific to bash. ksh, zsh, and coreutils seem compare mtime with sub-second precision.
https://lists.gnu.org/archive/html/bug-bash/2017-06/msg00010.html
Fixed in upstream http://git.savannah.gnu.org/cgit/bash.git/commit/?id=b90cb5a280ebb8ac03306a5b19aea6b997c71ee7
bash-4.4.12-6.fc26 has been submitted as an update to Fedora 26. https://bodhi.fedoraproject.org/updates/FEDORA-2017-2b6507886b
bash-4.4.12-6.fc26 has been pushed to the Fedora 26 testing repository. If problems still persist, please make note of it in this bug report. See https://fedoraproject.org/wiki/QA:Updates_Testing for instructions on how to install test updates. You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-2b6507886b
bash-4.4.12-6.fc26 has been pushed to the Fedora 26 stable repository. If problems still persist, please make note of it in this bug report.