Quick take: The date command prints the current date and time, and formats it any way you like with + specifiers: date '+%Y-%m-%d' gives 2026-06-14. It is widely used to timestamp filenames and logs in scripts.
Introduction
The date command displays and formats the system date and time, and (as root) can set it. Its real power is the formatting syntax, which lets scripts produce timestamps for filenames, log entries, and reports in exactly the format they need — plus simple date arithmetic for things like “yesterday” or “next week”.
Syntax
The basic syntax of the date command is:
date [OPTIONS] [+FORMAT]Common Options and Parameters
The most useful options and parameters for the date command:
| Option | Description |
|---|---|
| +FORMAT | Format output using specifiers (%Y, %m, %d, %H…). |
| -d STRING | Display a date described in words ('next friday'). |
| -u | Show or set UTC time. |
| -s STRING | Set the system date and time (root). |
| -r FILE | Show a file's last modification time. |
| %Y %m %d | Year, month, day. |
| %H %M %S | Hour, minute, second. |
| %s | Unix timestamp (seconds since 1970). |
Practical Examples
Real date commands you can run today:
# Current date and time
date
# ISO date for a filename
date '+%Y-%m-%d'
# Date and time stamp
date '+%Y-%m-%d_%H-%M-%S'
# Use in a backup filename
tar -czf "backup-$(date +%F).tar.gz" /data
# What was yesterday's date?
date -d 'yesterday' '+%Y-%m-%d'
# Unix timestamp
date '+%s'Tips and Best Practices
$(date +%F)produces an ISO date (2026-06-14) ideal for sortable, timestamped filenames.- Use
-dfor date math in plain English:date -d '7 days ago'ordate -d 'next monday'. - Prefer
timedatectlto set the clock and timezone on systemd systems;date -sworks but does not handle the timezone or NTP.
Final Thoughts
date is the go-to for showing, formatting, and computing dates and times. Its +FORMAT specifiers make it indispensable for timestamping files and logs in scripts, and -d handles plain-English date math. For setting the clock and timezone on modern systems, reach for timedatectl instead of date -s.
FAQ: date Command in Linux
How do I format the date in Linux?+
Use a + format string: date '+%Y-%m-%d' gives 2026-06-14, and date '+%H:%M:%S' gives the time. Combine specifiers however you need.
How do I add a date to a filename?+
Use command substitution: tar -czf backup-$(date +%F).tar.gz /data inserts the ISO date. %F is shorthand for %Y-%m-%d.
How do I get yesterday's or a future date?+
Use -d with a phrase: date -d 'yesterday' '+%F' or date -d 'next friday' '+%F'. date understands plain-English relative dates.
How do I get a Unix timestamp?+
Use date +%s, which prints the number of seconds since 1 January 1970. date -d @1700000000 converts a timestamp back to a readable date.
How do I set the system date?+
On systemd systems use timedatectl set-time '2026-06-14 09:00:00', which handles the timezone and clock properly. date -s works but is lower-level and ignores NTP.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support