/etc/localtime 应该是符号链接还是文件?

/etc/localtime 应该是符号链接还是文件?

首次安装 RHEL 系统时,我会选择时区。检查/etc/localtime,我发现这是 中的一个文件的副本/usr/share/zoneinfo

然而,当我考虑更改系统上的时区时,我发现复制新文件和创建符号链接之间存在分歧。

什么是公认的最佳实践?符号链接还是复制?

另外:有人有解决方案来确定系统当前设置的时区吗? 中的信息/etc/sysconfig/clock可能不正确。

答案1

根据本文档它应该是一个符号链接:

Name

localtime — Local timezone configuration file
Synopsis

/etc/localtime -> ../usr/share/zoneinfo/…
Description

The /etc/localtime file configures the system-wide timezone of the local system that is used by applications for presentation to the user. It should be an absolute or relative symbolic link pointing to /usr/share/zoneinfo/, followed by a timezone identifier such as "Europe/Berlin" or "Etc/UTC". The resulting link should lead to the corresponding binary tzfile(5) timezone data for the configured timezone.

Because the timezone identifier is extracted from the symlink target name of /etc/localtime, this file may not be a normal file or hardlink.

The timezone may be overridden for individual programs by using the TZ environment variable. See environ(7).

You may use timedatectl(1) to change the settings of this file from the command line during runtime. Use systemd-firstboot(1) to initialize the time zone on mounted (but not booted) system images.

为了确定时区,以下命令可以发出:

[vagrant@localhost ~]$ cat /etc/sysconfig/clock
ZONE="UTC"

答案2

Debian 维护人员在此错误报告中解释了他们的选择: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=726256

摘录如下:

Michael Biebl 写道:

通过 timedated(org.freedesktop.timedate1 或 timedatectl)更改时区信息将使用指向 /usr/share/zoneinfo 中的时区文件的符号链接替换 ​​/etc/localtime。

这意味着该文件在早期启动期间将是悬空符号链接,并且对于具有单独 /usr 的系统,时间可能会被错误设置。

相关内容