Why is /etc/localtime a symbolic link?
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
Related videos on Youtube
yael
Updated on September 18, 2022Comments
-
yael over 1 year
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?
-
Satō Katsura almost 8 yearsYour
/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. -
yael almost 8 yearsthx , 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 almost 8 yearsanother 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 almost 8 yearsthx 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
-
Stephen Harris almost 8 yearsThe 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 useUTC
. You can get more detail fromman 3 tzset
. -
Slaven Rezic almost 7 years@StephenHarris: I don't find a reference to the last fallback to UTC, at least not in the CentOS6 variant of the tzset manpage.
-
Stephen Harris almost 7 years@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. -
Fajela Tajkiya about 2 yearsHi @StephenHarris, What do you mean by "you must change /etc/sysconfig/clock as well"? How to change it? I'm on RHEL 6 and there is no timedatectl.