The GNU implementation of the date command has a nice feature to show the date of the last modification of a reference file, and using the +FORMAT parameter it is easy to get the date in any format, for example:
date -r /etc/motd +%Y%m%d_%H%M%S
# output in the format: 20121001_171233
Is there an equivalent in Solaris? I know I can do it using the stat function of perl like this:
perl -mPOSIX -e 'print POSIX::strftime("%Y%m%d_%H%M%S\n", localtime((stat("/etc/motd"))[9]))'
But isn't there a more elegant way?
UPDATE
This gives the same output as the perl script and it's "easier" for me:
ls -Ego /etc/motd | awk '{print $4 "_" $5}' | tr -d :- | sed -e 's/\..*//'
And yeah, probably there's no more elegant solution.