Set time in Linux

This document explains how to set your computer’s clock from Linux and how to set timezone. On Linux systems, you have a choice of keeping the hardware clock in UTC/GMT time or local time.

How to Set timezone

The timezone under Linux is set by a symbolic link from /etc/localtime to a file in the /usr/share/zoneinfo directory that corresponds with what timezone you are in. For example, since I’m in India ,/etc/localtime is a symlink to /usr/share/zoneinfo/Asia/Kolkata. To set this link, type:

ln -sf /usr/share/zoneinfo/your/zone /etc/localtime

Set up UTC or local time

When Linux boots, one of the initialisation scripts will run the /sbin/hwclock program to copy the current hardware clock time to the system clock. hwclock will assume the hardware clock is set to local time unless it is run with the --utc switch. Rather than editing the startup script, under Red Hat Linux you should edit the /etc/sysconfig/clock file and change the “UTC” line to either “UTC=true” or “UTC=false” as appropriate.

Set the hardware clock

To set the hardware clock, my favourite way is to set the system clock first, and then set the hardware clock to the current system clock by typing “/sbin/hwclock --systohc” (or “/sbin/hwclock --systohc --utc” if you are keeping the hardware clock in UTC). To see what the hardware clock is currently set to, run hwclock with no arguments. If the hardware clock is in UTC and you want to see the local equivalent, type “/sbin/hwclock --utc

This entry was posted in Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.