Where to start First steps track · 15 stages
Linux Labs

date — date and time in the shell

4 min GNU coreutils

The date command: current time, output formats, timestamps for files and logs, date arithmetic.

Cheat sheet

9 commands Printable version
  • date +%F 2026-06-30 (=%Y-%m-%d)
  • date +%Y%m%d-%H%M%S a timestamp for filenames
  • date +%s epoch: seconds since 1970
  • date -d @1700000000 epoch → human-readable
  • date -d "yesterday" +%F yesterday
  • date -d "now + 1 hour" +%T an hour from now
  • TZ='UTC' date current time in another timezone
  • date -Iseconds ISO 8601
  • tar czf "bk-$(date +%F).tgz" /etc a date in a backup's name

Overview

date prints and formats the date/time. In scripts (bash-scripting), it's used for timestamps in backup and log filenames. (System time and timezone are configured with timedatectl.)

bash
date                              # current date/time (local timezone)
date -u                          # in UTC
date +%Y-%m-%d                    # 2026-06-30 (a chosen format)
TZ='America/New_York' date        # show it in another timezone once

Options

6

Below are the main flags of date; the full list is in man date (the +%… format specifiers are a separate topic, see the table under "Recipes").

Option What it does Example
-u --utc Show the time in UTC instead of the local timezone. date -u
-d --date string Show a date parsed from a string (a timestamp, "yesterday", "now + 1 hour"), not the current one. date -d "yesterday" +%F
-I --iso-8601 date|hours|minutes|seconds Print the date/time in ISO 8601 format. date -Iseconds
-R --rfc-email Print the date in RFC 5322 format (for mail and HTTP headers). date -R
-s --set string Set the system clock manually; use timedatectl for regular synchronization. dangerous sudo date -s "2026-06-30 14:00:00"
-f --file datefile Read and print one date per line from a file. date -f dates.txt

Nothing found. Try a shorter query.

Recipes

2

Formats

bash
date +%F                          # 2026-06-30  (=%Y-%m-%d)
date +%T                          # 14:30:05    (=%H:%M:%S)
date +%Y%m%d-%H%M%S               # 20260630-143005 (for filenames)
date +%s                         # Unix timestamp (seconds since 1970)
date -d @1700000000              # timestamp → human-readable
date -Iseconds                   # ISO 8601: 2026-06-30T14:30:05+03:00
date -R                          # RFC 5322 (for mail/HTTP)
date '+%A, %d %B %Y'             # weekday and month spelled out (locale-dependent, see locale)

Specifiers: %Y/%m/%d year/month/day, %H:%M:%S time, %s epoch, %F/%T date/time, %j day of year, %A/%B weekday/month spelled out, %z offset.

Timestamps and arithmetic

bash
# a dated backup name
tar czf "backup-$(date +%F).tar.gz" /etc        # %F = %Y-%m-%d

# relative dates (-d)
date -d "yesterday" +%F
date -d "now + 2 hours" +%T
date -d "2026-01-01 + 30 days" +%F
date -d "last monday" +%F

# difference: via timestamps
echo $(( ($(date -d "2026-07-01" +%s) - $(date +%s)) / 86400 ))   # days until a date

# set the system clock manually (usually unnecessary — there's NTP):
sudo date -s "2026-06-30 14:00:00"        # prefer timedatectl instead

Troubleshooting

4

Spaces/colons ended up in a filename

date prints with spaces/: by default (bad for filenames). Use a format: date +%Y%m%d-%H%M%S or %F.

The time is wrong / the wrong timezone

date uses the system timezone. Check/change it via timedatectl; for UTC, use date -u; for another zone once, TZ='Europe/London' date. A drifting clock — NTP is covered in timedatectl.

Month/weekday names are in English but I need Russian

It depends on the locale (LC_TIME). Set the locale you need (see locale): LC_TIME=ru_RU.UTF-8 date '+%A %d %B'.

I need a timestamp in a script's logs

printf '%s %s\n' "$(date -Iseconds)" "message", or use the systemd journal (journalctl adds timestamps itself).

See also

  • timedatectl — System time, timezone, and NTP synchronization (systemd-timesyncd).
  • bash-scripting — Variables, conditionals, loops, arguments, and the safe mode set -euo pipefail.
  • files-basics — Navigation and files — ls, cd, cp, mv, rm, cat, less, head, tail, terminal copy-paste.
Loading…