zoukankan      html  css  js  c++  java
  • Linux系统时间硬件时间(date、tzselect、clock、hwclock、ntpdate)

    1、系统时间和硬件时间

    在Linux中有硬件时钟与系统时钟两种时钟。硬件时钟是指主机板上的时钟设备,也就是通常可在BIOS画面设定的时钟。系统时钟则是指kernel中的时钟。所有Linux相关指令与函数都是读取系统时钟的设定。因为存在两种不同的时钟,那么它们之间就会存在差异。当Linux启动时,系统时钟会去读取硬件时钟的设定,之后系统时钟即独立运作。

    用date命令对系统时间进行设置后,并不会去修改硬件时钟,所以系统重启后,系统时间还算会去读取硬件时间,这就是为何date设置失效到原因。

    因此,需要在设置系统时间后,将系统时间同步到硬件时钟。

    2、系统时间

    查看时间:date

    查看时区:date -R

    修改时间:date -s  (date -s 06/22/96, date -s 13:52:00)

    修改时区:tzselect #按照提示进行选择时区

    将当前时间和日期写入BIOS,避免重启后失效:hwclock -w

    3、硬件时间

    clock/hwclock两个命令相同

    命令参数:

    -r, --show        读取并打印硬件时钟(read hardware clock and print result)
    -s, --hctosys    将硬件时钟同步到系统时钟(set the system time from the hardware clock)
    -w, --systohc    将系统时钟同步到硬件时钟(set the hardware clock to the current system time)

    4、同步网络时间

    ntpdate 210.72.145.44

    定时同步时间:* * * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1

    (210.72.145.44 中国西安授时中心的官方时间同步服务器IP域名)

    5、用配置文件

    也可以用配置文件搞时区,但不建议这么弄,就不学习它了,其他的能不能配置文件搞不清楚。

    6、cal日历命令

    • -j 年里边第几天
    • -y 整年的日历
  • 相关阅读:
    一些有用的正则
    UNION ALL合表查询
    远程桌面连接:出现身份验证错误,要求的函数不受支持,可能是由于CredSSP加密Oracle修正的解决方法
    Ubuntu20.04安装、配置openvas
    awvs13破解安装、批量扫描脚本
    剑指05题
    时间复杂度o(1), o(n), o(logn), o(nlogn)
    Intellij IDEA 注释模板
    Explain详解
    Hibernate中get()和load()的区别
  • 原文地址:https://www.cnblogs.com/daduryi/p/6679524.html
Copyright © 2011-2022 走看看