Has the GNU coreutils (8.6) version of stat changed? After a recent update, some scripts I wrote that call stat are not working as expected; in particular, I had been making use of stat -c %Y "${filename}". This is supposed to return the time of last modification in the form of seconds since "Epoch". However, I could have sworn this used to take the form of a whole integer. However, I'm now getting output from this of the form 1287630625.956667227 rather than 1287630625. Since Bash can't handle floating point arithmetic, this is a litttle annoying. Is this a deliberate change? Or a bug? Or has my memory gone fuzzy? I tried searching for information on this, but couldn't find anything.

  • 2
    I wanted to come back and note that they've reverted to the old behavior for version 8.7 of coreutils, though if you want the decimal places, you can use, e.g., stat -c $.5Y filename to get 5 decimal places. Otherwise you get none. – frabjous Nov 21 '10 at 20:55

stat: print timestamps to full resolution was committed to coreutils-8.6.

$ git clone git://git.savannah.gnu.org/coreutils.git
$ cd coreutils
$ git log -1 --grep=time -- src/stat.c
commit 9069af45e691d1252c727da66aa4f3f3c7f1ea29
Author: Eric Blake 
Date:   Thu Sep 30 16:42:13 2010 -0600

    stat: print timestamps to full resolution

    * src/stat.c (epoch_time): New function.
    (print_stat): Use it for %[WXYZ].
    * NEWS: Document this.
    * tests/touch/60-seconds: Adjust test to match.
    * tests/misc/stat-birthtime: Likewise.
$ git describe --contains 9069af4
  • Thanks. One would have thought that for backwards compatibility they would have introduced an alternative notation and not replaced %[WXYZ]. – frabjous Oct 21 '10 at 16:29

This was unnecessarily disruptive and was reverted for coreutils8.7.
Since then you need to specify %.Y etc to get the fractional part included

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.