[OS X] Last modification time from shell in CCYYMMDDhhmm.ss format

This example shows last mtime from epoch

$ stat -f %m somefile
752911565

But would like to see it like that:

199311100606.05

Longhand using OSX 10.7.5, default bash terminal...

Last login: Sun Dec 14 12:48:13 on ttys000
AMIGA:barrywalker~> epoch=$(stat -f %m AudioScope.sh)
AMIGA:barrywalker~> date -r $epoch +%Y%m%d%H%M.%S
201412071947.59
AMIGA:barrywalker~> _

man stat and man strftime for more details.

stat -f "%Sm" -t "%Y%m%d%H%M.%S" FILE
1 Like