Get seconds since Epoch in Bash
bash 5.0 natively supports retrieving seconds since Epoch using a variable.
Native bash method
1echo $EPOCHSECONDS # 1682740449If seconds are preferred:
1echo $EPOCHREALTIME # 1682740449.252199If milliseconds are preferred:
1echo $(( ${EPOCHREALTIME/./} / 1000 )) # 1682740449252Using date
In addition to using the native bash method, date may be used.
According to the date manual:
%s seconds since the Epoch (1970-01-01 00:00 UTC)
1echo $(date +%s) # 1682740326If milliseconds seconds are preferred:
1echo $(date +%s%3N) # 1682740449252