为什么 /etc/localtime 是符号链接?

yae*_*ael 1 rhel etc symlink timezone

众所周知,为了设置新的时区需要执行以下步骤

当我们想要 UTC 时间时的示例

  unlink /etc/localtime   
  ln -s /usr/share/zoneinfo/UTC /etc/localtime
Run Code Online (Sandbox Code Playgroud)

所以我们创建了从 UTC 到 /etc/localtime 的符号链接

我只是想知道为什么我们需要创建链接,

而不仅仅是复制文件

/usr/share/zoneinfo/UTC 到 /etc/localtime为:

cp /usr/share/zoneinfo/UTC /etc/localtime
Run Code Online (Sandbox Code Playgroud)

复制文件有什么问题?

Ste*_*ris 7

您在标签中提到了 RHEL,所以我认为这就是您正在使用的。

对于 RHEL 6 及更早版本,当您升级tzdata包时,它会触发tzdata-update. 这读取/etc/sysconfig/clockZONE变量,将更新/etc/localtime是必要的。

这意味着如果你改变了什么/etc/localtime,那么你也必须改变/etc/sysconfig/clock,否则下次有tzdata补丁时你的改变可能会丢失。

使用 RHEL7,您应该timedatectl set-timezone用来管理时区。

# 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
Run Code Online (Sandbox Code Playgroud)