Skip to content

linux date tricks

Get current timestamp

date +%s
# Bash version >5
echo $EPOCHSECONDS

Get date from file reference

date -Ins -r /etc/hosts

Get date from timestamp

date -d @1713440994
Thu Apr 18 02:49:54 PM EEST 2024
### Without MSEC !!!
date -d @1713440994420
Sun Oct 14 02:47:00 AM EEST 56266

Date for scripts

$(date +"%Y%m%d_%H%M%S")
filename=file-$(date +"%Y%m%d_%H%M%S").log