8

留白1992的个人空间

 3 years ago
source link: https://my.oschina.net/codingcloud/blog/5023351
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Linux - 查看、修改、更新系统时间

本文以 CentOS 为例,演示如何查看、设置系统时间,以及自动从互联网更新系统时间。

查看系统时间

执行 date 命令可以查看当前系统的时间: 原文:Linux - 查看、修改、更新系统时间(自动同步网络时间)

手动修改系统时间

(1)执行如下命令可以设置一个新的系统时间:

date -s "20190712 18:30:50"

(2)设置完后还要执行如下命令保存一下设置:

hwclock --systohc

(3)当然我们也可以将上面两个操作合二为一:

date -s "20190712 18:30:50" &&hwclock --systohc

同步互联网时间

  1. 首先安装 ntpdate 命令:
yum install -y ntpdate
  1. 接着执行如下命令开始同步:
ntpdate 0.asia.pool.ntp.org

若上面的时间服务器不可用,也可以改用如下服务器进行同步:

time.nist.gov
time.nuri.net
0.asia.pool.ntp.org
1.asia.pool.ntp.org
2.asia.pool.ntp.org
3.asia.pool.ntp.org
  1. 最后执行如下命令将系统时间同步到硬件,防止系统重启后时间被还原。
hwclock --systohc

原文出自:https://www.hangge.com/blog/cache/detail_2499.html


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK