How to convert timestamps to dates in Bash?
On later versions of common Linux distributions you can use:
date -d @1267619929
This version is similar to chiborg's answer, but it eliminates the need for the external tty
and cat
. It uses date
, but could just as easily use gawk
. You can change the shebang and replace the double square brackets with single ones and this will also run in sh
.
#!/bin/bashLANG=Cif [[ -z "$1" ]]then if [[ -p /dev/stdin ]] # input from a pipe then read -r p else echo "No timestamp given." >&2 exit fielse p=$1fidate -d "@$p" +%c