How to set the date and time in Linux


You have at least 2 methods for setting the date and time in Linux:

  1. You can set the time by hand, but be careful, lots of clocks tend to drift over time. The trick here to make the time stick across a reboot is to run the hwclock command as shown below
  2. You can use NTP (Network Time Protocol) to get accurate time from a network time server (Atomic Clock). I highly recommend using NTP to keep your time set correctly: ntp.html

Note: Just using the date command alone will not cause the date to remain after a reboot. The date command sets the Linux system clock which is separate from the hardware clock. The “hwclock –utc –systohc” command is used to update the hardware clock with the date from the Linux system clock.

Run the date command to make sure you have the correct time:

[root@server /root]# date
Thu Sep 20 11:00:06 CDT 2001
[root@server /root]#

If you have the wrong timezone set, use “timeconfig” or “linuxconf” to set the correct timezone.

If your timezone is correct but the date and/or time needs updating, the following commands will update the date and time. The second command is needed in order to push the date and time into the PC clock.

[root@server /root]# date 092011082001
Thu Sep 20 11:08:00 CDT 2001
[root@server /root]# hwclock --utc --systohc
[root@server /root]#
Advertisements

About Amol

I'm blogger, avid read, photographer and book lover. Reading a lot of good stuff and sharing it with the world are my passions.
This entry was posted in Linux, Tricks and Tips. and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s