2023年12月2日发(作者:)

Linux命令-更新系统时间和硬件时间查看系统时间和时区:date 查看系统时间date -R 查看时区修改时区:tzselect 修改时区

或cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 上海时间或rm /etc/localtimeln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 上海时间ln -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime 洛杉矶时间修改时钟文件:/etc/sysconfig/clock修改为:ZONE="Asia/Shanghai"UTC=falseARC=false修改系统时间:

加入定时任务echo “*/10 * * * * systemctl restart chronyd && chronyc sources -v” >> /var/spool/cron/root

date 查看当前系统时间yum install -y ntpdate #centos7安装ntpdate程序yum install chrony #centos8安装ntpdate程序ntpdate 从互联网更新系统时间ntpdate 从互联网更新系统时间date 再次查看当前系统时间如果ntpdate 出错了.lsof -i:123 查看123端口使用情况kill -9 1469 杀死进程ntpdate 同步时间查看同步BIOS时钟,强制把系统时间写入CMOSclock --show 查看硬件时间clock -w 强制把系统时间写入CMOSclock --show 查看硬件时间reboot 重起机器重新启动系统,硬件时间会读取系统时间,实现同步;但是在不重新启动的时候,需要用hwclock或clock命令实现同步。硬件时钟与系统时钟同步:hwclock --hctosys (hc代表硬件时间,sys代表系统时间)或者 clock --hctosys系统时钟和硬件时钟同步:hwclock --systohc或者 clock --systohc让linux自动从自动同步时间vi /etc/crontab加上一句自动同步时间:00 0 1 * * ntpdate -s --每天凌晨1点* */1 * * * ntpdate -s --每一个小时* */1 * * * ntpdate -s