Linux命令-更新系统时间和硬件时间


查看系统时间和时区:

date 查看系统时间
date -R 查看时区

修改时区:

tzselect  修改时区 

 或

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 上海时间

rm /etc/localtime ln -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=false ARC=false

修改系统时间:

date 查看当前系统时间 yum install -y ntpdate 安装ntpdate程序 ntpdate time.windows.com 从互联网更新系统时间
ntpdate cn.pool.ntp.org 从互联网更新系统时间 date 再次查看当前系统时间

如果ntpdate time.windows.com出错了.

lsof -i:123 查看123端口使用情况
kill -9 1469 杀死进程
ntpdate time.windows.com 同步时间

查看linux lsof详解

同步BIOS时钟,强制把系统时间写入CMOS

clock --show   查看硬件时间
clock -w       强制把系统时间写入CMOS
clock --show   查看硬件时间
reboot 重起机器

重新启动系统,硬件时间会读取系统时间,实现同步;但是在不重新启动的时候,需要用hwclock或clock命令实现同步。

硬件时钟与系统时钟同步:hwclock --hctosys (hc代表硬件时间,sys代表系统时间)或者 clock --hctosys
系统时钟和硬件时钟同步:hwclock --systohc或者 clock --systohc

让linux自动从time.windows.com自动同步时间

vi /etc/crontab

加上一句自动同步时间:

00 0 1 * * ntpdate -s time.windows.com --每天凌晨1点
* */1 * * * ntpdate -s time.windows.com --每一个小时
* */1 * * * ntpdate -s cn.pool.ntp.org


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM