As @TomMcKenzie notes in a comment on another answer, date -r 123456789 may be a more common (i.e. more widely implemented) simple solution within seconds of Unix Epoch, but unfortunately there is no universal guaranteed portable solution.
The -d option for many types of systems means something completely different than the GNU Date --date . Unfortunately, GNU Date does not interpret -r in the same way as these other implementations. Unfortunately, you need to know which version of date you are using, and many older date Unix commands do not support any of the options.
Worse, POSIX date does not recognize either -d or -r and does not provide a standard way in any command at all (that I know) to format Unix time from the command line (since POSIX Awk also lacks strftime() ). (You cannot use touch -t and ls because the former does not accept the time specified in seconds since Unix.)
Note that although One True Awk, available directly from Brian Kernighan, now has a built-in strftime() function, as well as a systime() function to return the current time in seconds since Unix Epoch), so maybe the Awk solution is most portable.
Greg A. Woods Jan 01 '13 at 3:24 2013-01-01 03:24
source share