I'm running this shell command to get the most recent 20 PHP files modified on my server.

find . -name '*.php' -printf '%TY-%Tm-%Td %TH:%TM:%TS %Tz %p\n' | sort -r | head -20

The output is like this:

2016-08-08 01:44:45.3820716170 -0700 ./html/index.php
2016-08-07 05:39:29.0000000000 -0700 ./html/thumb.php
2016-08-07 03:01:44.0000000000 -0700 ./html/paths.php

According to strftime man page, I should just be able to use %S (and %TS)


The second as a decimal number (range 00 to 60). (The range is up to 60 to allow for occasional leap seconds.)

There is probably something going on with find, but the other time parameters work as expected. I'm trying to get results like the following. If the extra string is in fact fractional seconds, either rounding or truncating is fine. How can this be done?

2016-08-08 01:44:45 -0700 ./html/index.php
2016-08-07 05:39:29 -0700 ./html/thumb.php
2016-08-07 03:01:44 -0700 ./html/paths.php

(and if there is a more efficient way to do what the above command does, I'm all ears.)

  • My find man page says that S includes fractional seconds: "S Second (00.00 .. 61.00). There is a fractional part." and I don't note an option right off that doesn't Aug 8 '16 at 12:56
  • You might find some helpful suggestions at stackoverflow.com/questions/5566310/… Aug 8 '16 at 12:59
  • @EricRenouf Nice find on a better recursive find (forgive the pun). It would still be nice to remove the fractional seconds if even possible.
    – Drakes
    Aug 8 '16 at 13:10

You can truncate the fractional part using the %.n formatting syntax, where n is an integer specifying the length of the string you want to keep. In your particular case, the incantation would be:

find . -name '*.php' -printf '%TY-%Tm-%Td %TH:%TM:%.2TS %Tz %p\n' | sort -r | head -20


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.