date Command ExamplesThe 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.
Shows the current system date and time in the default format.
date
Example Output: Fri Oct 10 13:22:45 EDT 2025
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
Displays only the time using %H (hour), %M (minute), and %S (second).
date +"%H:%M:%S"
Example Output: 13:22:45
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
Shows the current date and time in Coordinated Universal Time (UTC).
date -u
Example Output: Fri Oct 10 17:22:45 UTC 2025
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
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
Shows only the day of the week using the %A format specifier.
date +"%A"
Example Output: Friday
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
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.