6

If I'm using stat to display the mtime, I get a date with milliseconds:

$ stat -c '%y' test.log 
2019-07-04 14:32:10.730059167 +0200

However, if I want to display the Epoch timestamp, I don't get milliseconds any more:

$ stat -c '%Y' test.log 
1562243530

Am I missing something or will I have to patch it together from both outputs?

1 Answer 1

7

For the GNU Coreutils implementation, you can use

stat --format='%.9Y' file

or just

stat --format='%.Y' file

From the info documentation:

The ‘%W’, ‘%X’, ‘%Y’, and ‘%Z’ formats accept a precision preceded by a period to specify the number of digits to print after the decimal point. For example, ‘%.3X’ outputs the access timestamp to millisecond precision. If a period is given but no precision, ‘stat’ uses 9 digits, so ‘%.X’ is equivalent to ‘%.9X’. When discarding excess precision, timestamps are truncated toward minus infinity.

2
  • 🤦 Thanks! Didn't think of looking at it's info page, only looked at man. But it makes sense, since it's a GNU tool.
    – finefoot
    Jul 13, 2019 at 16:01
  • 1
    @finefoot yeah sometimes they hide extra nuggets in the info pages Jul 13, 2019 at 16:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .