700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > centos7查看当前系统时间 _CentOS 7修改系统时间及硬件时间

centos7查看当前系统时间 _CentOS 7修改系统时间及硬件时间

时间:2022-04-10 12:25:42

相关推荐

centos7查看当前系统时间 _CentOS 7修改系统时间及硬件时间

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

先看下命令帮助:

[root@nginx ~]# timedatectl --help

timedatectl [OPTIONS...] COMMAND ...

Query or change system time and date settings.

-h --help Show this help message

--version Show package version

--no-pager Do not pipe output into a pager

--no-ask-password Do not prompt for password

-H --host=[USER@]HOST Operate on remote host

-M --machine=CONTAINER Operate on local container

--adjust-system-clock Adjust system clock when changing local RTC mode

Commands:

status Show current time settings

set-time TIME Set system time

set-timezone ZONE Set system time zone

list-timezones Show known time zones

set-local-rtc BOOL Control whether RTC is in local time

set-ntp BOOL Control whether NTP is enabled

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

[root@tgcdn-qd-133 /root]

#timedatectl

Local time: Tue -03-13 10:41:20 CST

Universal time: Tue -03-13 02:41:20 UTC

RTC time: Tue -03-13 02:42:29

Time zone: Asia/Shanghai (CST, +0800)

NTP enabled: n/a

NTP synchronized: no

RTC in local TZ: no

DST active: n/a

设置当前时间:

timedatectl set-time HH:MM:SS

设置当前日期:

timedatectl set-time YYYY-MM-DD

默认的,系统是使用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参数进行远程主机的时间设置。

查看系统时间

[root@nginx ~]# date

03月 13日 星期二 10:58:41 CST

查看硬件时间

[root@nginx ~]# hwclock --show

03月13日 星期二 11时00分16秒 -0.086030 秒

假如系统时间和硬件时间都不准确

更新时区

[root@localhost ~]# timedatectl set-timezone Asia/Shanghai

更新日期

[root@localhost ~]# timedatectl set-time -06-13

更新时间

[root@localhost ~]# timedatectl set-time -06-13

将系统时间和硬件时间调整为一致

[root@localhost ~]# timedatectl set-local-rtc 1

或者

[root@localhost ~]# hwclock --systohc --localtime

将日期写入CMOS

[root@localhost ~]# clock –w

转载至/shudaqi/article/details/77977532

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。