Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

date

Show the date and time in any format, calculate other dates, or set the system clock.

Level
RHCSA exam
Group
Time
Needs root
For changes
Package
coreutils

What it does

date prints the current time in your time zone. +FORMAT controls the output (%F = 2026-10-25), -d shows another moment ("tomorrow", "+3 days", "@EPOCH"), -u uses UTC. root can set the clock with -s, but on a system with NTP chrony will correct it — use timedatectl and chrony instead.

How to write it

date [OPTION]... [+FORMAT]
date [-u] -s "DATE TIME"

Main parts

%F
Date: 2026-10-25.
%T
Time: 11:42:10.
%Y %m %d
Year, month, day.
%H %M %S
Hour, minute, second.
%s
Seconds since 1970-01-01 UTC (epoch).
%a %A / %b %B
Short/long day name / month name.
%j
Day of the year.
%u
Day of the week (1 = Monday).
%V
ISO week number.
%z %Z
Time zone offset / name.
%N
Nanoseconds.

Options 12

Most used

-d, --date=STRING
Show this moment instead of now: "yesterday", "+2 hours", "next monday", "@1761389000".
-u, --utc, --universal
Use UTC.
-s, --set=STRING
Set the clock (root).
-I[FMT], --iso-8601[=FMT]
ISO 8601 output (date, hours, minutes, seconds, ns).
--rfc-3339=FMT
RFC 3339 output (date, seconds, ns).
-R, --rfc-email
RFC 5322 (mail) format.
-r, --reference=FILE
Show the change time of a file.
-f, --file=FILE
Like -d for each line of a file.
--debug
Show how the date string was understood.
--resolution
Show the time resolution.
--help
Show help.
--version
Show the version.

Examples 11

$ run as a normal user# run as root (or with sudo)

  1. 1Now

    date
    Sun Oct 25 11:42:10 +03 2026

    Local time zone.

  2. 2A file-name friendly stamp

    tar -czf /backup/etc-$(date +%F_%H%M).tgz /etc

    etc-2026-10-25_1142.tgz.

  3. 3UTC

    date -u

    Same moment in UTC (logs from many servers).

  4. 4Calculate dates

    date -d '+30 days' +%F
    date -d 'last friday' +%F

    Expiry dates for chage -E.

  5. 5Epoch seconds

    date +%s
    1761381730
    date -d @1761381730

    Convert log time stamps.

  6. 6ISO format

    date -Iseconds
    2026-10-25T11:42:10+03:00

    For JSON and APIs.

  7. 7Time of a file change

    date -r /etc/passwd

    When was a user changed?

  8. 8Time in another zone

    TZ=Europe/Amsterdam date

    Without changing the system.

  9. 9Set the clock (lab without NTP)

    timedatectl set-ntp false; date -s "2026-10-25 12:00:00"

    With NTP on, chrony corrects it.

  10. 10Days until a certificate expires (security)

    echo $(( ( $(date -d "$(openssl x509 -enddate -noout -in /etc/pki/tls/certs/site.crt | cut -d= -f2)" +%s) - $(date +%s) ) / 86400 ))

    Alert when it gets low.

  11. 11Measure how long something takes

    S=$(date +%s); sleep 2; echo "took $(( $(date +%s) - S )) s"

    Simple timing in scripts.

Exit codes

0Done.
1Error.