centos命令篇--修改系统时钟

查看软件时钟 date 命令

a: date 直接修改 系统时钟(手动)
格式 [MMDDhhmm[[CC]YY][.ss]]
例如: 2019.7.23 15.00

[root@uplooking ~] # date 072315002019.40
                                          #月日时分年秒
b: 格式化 时间格式,用于 命名 备份文件
备份 /shell 目录, 以当前的 年月日 时分 命名
[root@uplooking ~] # cd /
[root@uplooking /] # tar -zcvf shell_`date +%F-%H-%M`.tar.gz shell/
结果:shell_2019-07-23-14-07.tar.gz
c: 随机数种子
date +%N

#查看
echo $RANDOM

d:打印绝对秒数
date +%s
至1970年1月1日到 当前时间所经过的绝对秒数。


2、 硬件时钟 hwclock 命令

hwclock 查询硬件时钟
hwclock --systohc 根据 sys 设置 hw (多)
--hctosys 根据 hw 设置 sys

----------------------------------------------------------------------------------------------------------------

3、 软硬件时钟都出错,如何调整

(1、查看 时区是否正确
[root@uplooking ~] # ls -l /etc/localtime
[root@uplooking ~] # lrwxrwxrwx 1 root root 33 7月 23 15:06 /etc/localtime -> /usr/share/zoneinfo/Asia/Shanghai

(2、 时区文件存放的路径 /usr/share/zoneinfo 下
(3、修改 时区,删除软连接,重新建立软连接即可
[root@uplooking ~] # rm /etc/localtime
[root@uplooking ~] # ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[root@uplooking ~] # date 验证
------------------------------------------------------------------------------------------------------------------

网络时钟 同步服务:

安装同步客户端工具 ntpdate
[root@uplooking ~] # yum install ntpdate -y
[root@uplooking ~] # ping ntp1.aliyun.com   ##是否能通阿里源?
[root@uplooking /]# ntpdate ntp1.aliyun.com

输出以下结果,说明成功了
23 Jul 15:19:32 ntpdate[9713]: adjust time server 120.25.115.20 offset 0.048863 sec
------------------------------------------------------------------------------------------------------------------
当硬件时间有误,先软件同步阿里云时间,再硬件同步软件时间

[root@uplooking /]# hwclock --systohc    #硬件同步软件的时间  的命令

[root@uplooking /]# hwclock --hctosys    #软件同步硬件的时间   的命令



posted @ 2022-02-15 10:43  捏你小脸  阅读(503)  评论(0)    收藏  举报