Sep 18, 2018

f Comment

Unix: How do you correct the system date and time WITHOUT manually entering the date and time?

Amazon Suppose your Unix machine's system time is wrong. How do you correct it? How do you automatically set your Unix server's system time to the correct global clock so you don't need to manually key in the correct time? In other words, how do you set the Unix system date and time correctly in a non-manual way? Let's find out.

First, you run the command date to show the current date and time on your Linux machine:

# date
Wed Sep 19 10:11:01 CST 2018

It's wrong; the correct time should be 10:16. It's five minutes behind.

You run the following command to show the hardware date and time:

# hwclock --show
Wed 19 Sep 2018 10:16:34 AM CST -1.010401 seconds

It turns out that the hardware date and time is correct! So you'd like to synchronize system time to hardware clock on your Linux box. In other words, you want to set the system time to the hardware clock.

Here's the command:

# hwclock --hctosys

Run date again immediately to see the time change:

# date
Wed Sep 19 10:17:01 CST 2018

Shortly, run date again to make sure the clock is really running!

# date
Wed Sep 19 10:17:14 CST 2018

Luckily our hardware date and time on the Unix box is correct. Suppose it is wrong, what do you do? If this happens to me, let me know and I'll find a solution for you.

Questions? Let me know!
Please leave a comment here!
One Minute Information - by Michael Wen
ADVERTISING WITH US - Direct your advertising requests to Michael