Linux date Command Examples

The date command in Linux is used to display or set the system date and time. Below are 10 examples demonstrating various uses of the date command with detailed explanations.

1. Display Current Date and Time

Shows the current system date and time in the default format.

date

Example Output: Fri Oct 10 13:22:45 EDT 2025

2. Display Date in a Specific Format

Uses format specifiers to customize the output. For example, %Y for year, %m for month, and %d for day.

date +"%Y-%m-%d"

Example Output: 2025-10-10

3. Display Time Only

Displays only the time using %H (hour), %M (minute), and %S (second).

date +"%H:%M:%S"

Example Output: 13:22:45

4. Display Date and Time in ISO 8601 Format

Formats the output in the ISO 8601 standard, which is widely used for date-time representation.

date --iso-8601

Example Output: 2025-10-10T13:22:45-04:00

5. Display UTC Time

Shows the current date and time in Coordinated Universal Time (UTC).

date -u

Example Output: Fri Oct 10 17:22:45 UTC 2025

6. Set System Date

Sets the system date to a specific value (requires superuser privileges).

sudo date --set="2025-12-25"

Example Output: Thu Dec 25 00:00:00 EDT 2025

7. Set System Time

Sets the system time to a specific value (requires superuser privileges).

sudo date --set="15:30:00"

Example Output: Fri Oct 10 15:30:00 EDT 2025

8. Display Day of the Week

Shows only the day of the week using the %A format specifier.

date +"%A"

Example Output: Friday

9. Display Date in a Custom String

Combines multiple format specifiers to create a custom output string.

date +"Today is %A, %B %d, %Y"

Example Output: Today is Friday, October 10, 2025

10. Display Unix Timestamp

Shows the current Unix timestamp (seconds since Jan 1, 1970).

date +%s

Example Output: 1752213765

Note: The output of these commands depends on your system's timezone and locale settings. Use man date for more format specifiers and options.