1

as all know , in order to set new TIME ZONE need to perform the following steps

example when we want UTC time

  unlink /etc/localtime   
  ln -s /usr/share/zoneinfo/UTC /etc/localtime

so we create symbolic link from UTC to /etc/localtime

I just Wondering why we need to create link ,

And not just to copy the file

from /usr/share/zoneinfo/UTC to /etc/localtime as:

cp /usr/share/zoneinfo/UTC /etc/localtime

what is wrong about copy the file?

  • 1
    Your /etc/localtime won't be updated when timezone files are updated (this happens every few years, typically when some countries change their DST regulations). Linking makes sure it stays up to date. – Satō Katsura Jul 20 '16 at 16:25
  • thx , I have another question please , when /etc/localtime is file and not a link , and I want to remove this file and create a link , then what happens if I remove the /etc/localtime how date know what GMT to print ? , I ask this because I want to replace the file with a link on some critical servers that GMT is very important , ( fro example DB servers that connected to the aplication servers and when /etc/localtime is remove , need to verify if this action will cause problem – yael Jul 20 '16 at 16:29
  • another interesting thing is when I remove the /etc/localtime , then date became to UTC timezone , is it default to return to the UTC when /etc/localtime not exist ? – yael Jul 20 '16 at 16:36
6

You mention RHEL in your tags, so I assume this is what you're using.

With RHEL 6 and earlier, when you upgrade the tzdata package then it triggers tzdata-update. This reads /etc/sysconfig/clock for the ZONE variable, and will update /etc/localtime as necessary.

What this means is that if you change what /etc/localtime is then you must change /etc/sysconfig/clock as well, otherwise your change may be lost next time there's a tzdata patch.

With RHEL7 you should use timedatectl set-timezone to manage the timezones.

# date
Wed Jul 20 12:34:51 EDT 2016
# timedatectl set-timezone UTC
# ls -l /etc/localtime 
lrwxrwxrwx. 1 root root 25 Jul 20 16:35 /etc/localtime -> ../usr/share/zoneinfo/UTC
# date
Wed Jul 20 16:35:07 UTC 2016
# timedatectl set-timezone America/New_York
# ls -l /etc/localtime                     
lrwxrwxrwx. 1 root root 38 Jul 20 12:35 /etc/localtime -> ../usr/share/zoneinfo/America/New_York
# date                                     
Wed Jul 20 12:35:18 EDT 2016
  • thx for your answer , Just note - another interesting thing is when I remove the /etc/localtime , then date became to UTC timezone , is it default to return to the UTC when /etc/localtime not exist – yael Jul 20 '16 at 16:39
  • 1
    The standard order is to use the $TZ variable; if that doesn't exist then use the /etc/localtime file and if that doesn't exist then use UTC. You can get more detail from man 3 tzset. – Stephen Harris Jul 20 '16 at 16:44
  • @StephenHarris: I don't find a reference to the last fallback to UTC, at least not in the CentOS6 variant of the tzset manpage. – Slaven Rezic Aug 3 '17 at 16:37
  • @SlavenRezic In the Centos6 manpage it says " If the TZ variable does appear in the environment but its value is empty or its value cannot be interpreted using any of the formats specified below, Coordinated Universal Time (UTC) is used. ". Although the manpage doesn't state, this also happens if TZ is not set and /etc/localtime is not present. – Stephen Harris Aug 4 '17 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.