How to convert timestamps to dates in Bash?

chiborg picture chiborg · Mar 3, 2010 · Viewed 283.2k times · Source

I need a shell command or script that converts a Unix timestamp to a date. The input can come either from the first parameter or from stdin, allowing for the following usage patterns:

ts2date 1267619929

and

echo 1267619929 | ts2date

Both commands should output "Wed Mar 3 13:38:49 2010".

Answer

a'r picture a'r · Mar 3, 2010

On later versions of common Linux distributions you can use:

date -d @1267619929