Overview
date prints or sets the system date/time and formats timestamps. For timezone/NTP management prefer timedatectl.
Syntax
date [options] [+format]
date [-u] [-d timestr] [+format]
Common Options
-u |
UTC |
-d STR / --date= |
Parse string instead of now |
-f file |
Read dates from file |
-I[timespec] |
ISO-8601 |
-R |
RFC-5322 |
-s |
Set system time (needs root; prefer timedatectl) |
Examples with Explanations
date
date -u
date +%Y-%m-%d
date +%F_%H%M%S
date -Iseconds
date -d 'yesterday' +%F
date -d 'next Mon' +%F
date -d @1700000000
date -d '2 hours ago' +%T
Filenames / logs
logfile="/var/log/myapp-$(date +%F).log"
Epoch math
date +%s
date -d @$(( $(date +%s) + 3600 ))