在新的centos7裡,關于時間的指令除了保留了之前版本中常用到的date、hwclock等指令外,還增加了一個統一的指令timedatactl。下面結合其用法進行下小結。
檢視 timedatectl 指令用法幫助
[[email protected] ~]# 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=[[email protected]]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
[[email protected] ~]# 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參數進行遠端主機的時間設定。