一聚教程网:一个值得你收藏的教程网站

热门教程

centos 7 设置时间命令timedatectl用法示例

时间:2022-11-14 22:09:05 编辑:袖梨 来源:一聚教程网

在新的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

更详细的帮助信息也可以通过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

设置日期

timedatectl set-time YYYY-MM-DD

设置当前时间

timedatectl set-time HH:MM:SS

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

timedatectl set-local-rtc boolean

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

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

设置时区:

查看所有的时区:

timedatectl list-timezones

用以下命令设置时区:

timedatectl set-timezone time_zone

远程NTP服务器同步

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

timedatectl set-ntp boolean

这里的boolean是yes或者no

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

热门栏目