formatted modified date/time of file on mac bash? formatted modified date/time of file on mac bash? bash bash

formatted modified date/time of file on mac bash?


It's actually pretty simple, but different enough from GNU date that it's nowhere near obvious:

date -r $TIMESTAMP +%Y%m%dT%H%M%S

To get stat to do the formatting:

stat -f "%Sm" -t "%Y%m%dT%H%M%S" FILE


# how-to list all the files and dir in a dir sorted by their# modified time in the different shells # usually mac os / Unix / FreeBSD stat stat -f "%Sm %N" -t "%Y-%m-%d %H:%M:%S" ~/opt/comp/proj/*|sort # STDOUT output:# 2018-03-27 15:41:13 ~/opt/comp/proj/foo# 2018-03-28 14:04:11 ~/opt/comp/proj/bar# GNU Utils ( usually on Linux ) stat # STDOUT output:stat -c "%y %n" ~/opt/comp/proj/*|sort# 2018-03-29 09:15:18.297435000 +0300 ~/opt/comp/proj/bar# 2018-03-29 09:15:18.297435000 +0300 ~/opt/comp/proj/foo