如何在Debian 10上设置或者更改时区
对于许多与系统相关的任务和过程,使用正确的时区至关重要。
例如,cron守护程序使用系统的时区执行cron作业,而日志文件中的时间戳基于同一系统的时区。
在Debian上,系统的时区是在安装过程中设置的,但以后可以轻松更改。
本文介绍了如何在Debian 10 Linux上设置或者更改时区。
检查当前时区
“ timedatectl”是一个命令行实用程序,可让我们查看和更改系统的时间和日期。
它在所有基于systemd的现代Linux系统上都可用:
timedatectl
以下输出显示系统的时区设置为“ UTC”:
Local time: Fri 2017-04-03 19:23:29 UTC Universal time: Fri 2017-04-03 19:23:29 UTC RTC time: Fri 2017-04-03 19:23:29 Time zone: UTC (UTC, +0000) System clock synchronized: no NTP service: inactive RTC in local TZ: no
通过将“/etc/localtime”符号链接到“/usr/share/zoneinfo”目录中的二进制时区标识符来配置系统时区。
我们也可以使用'ls'命令通过检查符号链接指向的路径来找到时区:
ls -l /etc/localtime
lrwxrwxrwx 1 root root 23 Nov 21 23:44 /etc/localtime -> /usr/share/zoneinfo/UTC
在Debian中更改时区
在更改时区之前,我们需要找出要使用的时区的长名称。
时区使用“地区/城市”格式。
要列出所有可用时区,我们可以在“/usr/share/zoneinfo”目录中列出文件,或者使用“ list-timezones”选项调用“ timedatectl”命令:
timedatectl list-timezones
... America/Monterrey America/Montevideo America/Montserrat America/Nassau America/New_York ...
一旦确定了哪个时区适合位置,请以root或者具有sudo特权的用户身份运行以下命令:
sudo timedatectl set-timezone your_time_zone
例如,要将系统的时区更改为'America/Monterrey',我们可以运行:
sudo timedatectl set-timezone America/Monterrey
通过使用“ timedatectl”命令检查当前系统的时区来验证更改:
timedatectl
Local time: Fri 2017-04-03 13:30:30 CST Universal time: Fri 2017-04-03 19:30:30 UTC RTC time: Fri 2017-04-03 19:30:30 Time zone: America/Monterrey (CST, -0600) System clock synchronized: no NTP service: inactive RTC in local TZ: no
通过创建符号链接来更改时区
如果我们运行的是Debian的旧版本,并且系统上没有'timedatectl'命令,则可以通过将'/etc/localtime'文件符号链接到'/usr/share/zoneinfo中的时区二进制文件来更改时区。
' 目录。
确定要配置的时区,并创建一个符号链接:
sudo ln -sf /usr/share/zoneinfo/America/Monterrey /etc/localtime
通过列出“/etc/localtime”文件或者发出“ timedatectl”或者“ date”命令来验证更改:
date
Fri 03 Apr 2017 01:34:27 PM CST