查看修改Linux时区和时间

  一、时区

  1. 查看当前时区
  date -R
  2. 修改设置时区
  方法(1)
  tzselect
  方法(2) 仅限于RedHat Linux 和 CentOS
  timeconfig
  方法(3) 适用于Debian
  dpkg-reconfigure tzdata
  3. 复制相应的时区文件,替换系统时区文件;或者创建链接文件
  cp /usr/share/zoneinfo/$主时区/$次时区 /etc/localtime
  在中国可以使用:

  cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime


  二、时间
  1、查看时间和日期
  date
  2、设置时间和日期
  将系统日期设定成1996年6月10日的命令
  date -s 06/22/96
  将系统时间设定成下午1点52分0秒的命令
  date -s 13:52:00
  3. 将当前时间和日期写入BIOS,避免重启后失效
  hwclock -w


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

 

 在Linux中,用于时钟查看和设置的命令主要有date、hwclock和clock。其中,clock和hwclock用法相近,只用一个就行,只不过clock命令除了支持x86硬件体系外,还支持Alpha硬件体系。

  查看Linux系统时间:
date
  修改Linux系统时间:
date -s (后面跟时间)

  查看Linux硬件时间:
hwclock

clock

hwclock �Cshow

clock �Cshow

  修改Linux硬件时间:
hwclock �Cset �Cdate

clock �Cset �Cdate

  让系统时间与硬件时钟同步,用:
hwclock �Chctosys

clock �Chctosys

  相反地,让硬件时钟与系统时间同步:
hwclock �Csystohc

clock �Csystohc

  让系统时间每隔十分钟去同步一下硬件时间。

[hqw@localhost root]$ vi /etc/crontab    
SHELL=/bin/bash  
PATH=/sbin:/bin:/usr/sbin:/usr/bin  
MAILTO=root  HOME=/    
# run-parts  
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
*/10 * * * * root hwclock --hctosys  #我加入了这么一行,表示每隔10分钟执行一次hwclock --hctosys。



转载出处:http://blog.163.com/zilichen0213@126/blog/static/17303755520118423614908/

你可能感兴趣的:(Date,ntpdate,hwclock)