在新的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參數進行遠程主機的時間設定。