In Red Hat-based Linux distributions, you can use the date command to display or set the system’s date and time. Here’s how you can use the date command and its parameters, along with some examples:
| Parameter | Description | Example |
|---|---|---|
+%Y-%m-%d | Print year-month-day format | date +%Y-%m-%d |
+%H:%M:%S | Print hour:minute:second format | date +%H:%M:%S |
+%A | Print full weekday name | date +%A |
+%B | Print full month name | date +%B |
+%Z | Print timezone name | date +%Z |
--set | Set the system date and time (requires root privileges) | sudo date --set="2023-08-25 15:30:00" |
--help | Display help information for the date command | date --help |
Examples:
- Display the current date in the “year-month-day” format:
Bash
date +%Y-%m-%d- Display the current time in the “hour:minute:second” format:
Bash
date +%H:%M:%S- Display the current full weekday name:
Bash
date +%A- Display the current full month name:
Bash
date +%B- Display the current timezone:
Bash
date +%Z- Set the system date and time (requires root privileges):
Bash
sudo date --set="2023-08-25 15:30:00"Remember that setting the system date and time requires administrative privileges (sudo), and incorrect changes can potentially disrupt your system’s functioning. Always be cautious when using these commands, especially in a production environment.