centos7设置时间命令timedatectl

在新的centos7里,关于时间的指令除了保留了之前版本中常用到的date、hwclock等命令外,还增加了一个统一的命令timedatactl。下面结合其用法进行下小结。

查看 timedatectl 指令用法帮助

[root@361way ~]# timedatectl --help
timedatectl [OPTIONS...] COMMAND ...
Query or change system time and date settings.
  -h --help              Show this help
     --version           Show package version
     --adjust-system-clock
                         Adjust system clock when changing local RTC mode
     --no-pager          Do not pipe output into a pager
  -P --privileged        Acquire privileges before execution
     --no-ask-password   Do not prompt for password
  -H --host=[USER@]HOST  Operate on remote host
Commands:
  status                 Show current time settings
  set-time TIME          Set system time
  set-timezone ZONE      Set system timezone
  list-timezones         Show known timezones
  set-local-rtc BOOL     Control whether RTC is in local time
  set-ntp BOOL           Control whether NTP is enabled
<br />

更详细的帮助信息也可以通过man timedatectl 进行查看。

查看当前设置,直接输入timedatectl等同于timedatectl status 

[root@361way ~]# timedatectl
      Local time: Wed 2014-09-24 21:19:26 CST
  Universal time: Wed 2014-09-24 13:19:26 UTC
        RTC time: Wed 2014-09-24 13:19:26
        Timezone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
<br />

设置日期

timedatectl set-time YYYY-MM-DD
<br />

设置当前时间

timedatectl set-time HH:MM:SS
<br />

默认的,系统是使用UTC时间的,可以用以下命令打开和关闭UTC时间

timedatectl set-local-rtc boolean
<br />

把 boolean 替换成yes则表示使用本地时间,替换成no则表示是UTC时间

注:这里的boolean值也可以用true、flase

设置时区

查看所有的时区:

timedatectl list-timezones
<br />

用以下命令设置时区:

timedatectl set-timezone time_zone
<br />

远程NTP服务器同步

timedatectl还可以设置是否打开NTP选项

timedatectl set-ntp boolean
<br />

这里的boolean是yes或者no

除了以上用法,timedatectl 还支持通过-H参数进行远程主机的时间设置。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注