The date command can not only display the current time of the system, but also use it to modify the system time. The following is a brief introduction to facilitate the users who need it.
Command format:
Date-s time string
For example, you can modify only the system date without changing the time (hours, minutes, and seconds)
Date-s 2012-08-02
Or modify only the time without modifying the date
Date-s 10:08:00
Of course, you can also modify the date and time at the same time.
Date-s "04:53:00"
Note: Because there is a space between the date and time, it must be enclosed by quotation marks. Otherwise, an error is returned.
The above modification only modifies the linux system time, and the time in CMOS may not change. Therefore, we need to use clock-w to write the current system time to CMOS for insurance purposes.
The relationship between system time and CMOS time. The system time is maintained by the linux operating system, and the CMOS time is the time when the CMOS chip is saved. When the system starts, the operating system records the read time from CMOS as the system time, and the operating system automatically writes the system time to CMOS at intervals of time. If you use the date command to change the system time and restart the computer immediately, the operating system has not synchronized the system time to CMOS, so there is still no pre-modification time after the boot, so for the sake of security, you can also manually use the clock command to synchronize the system time to CMOS.