centos服务器修改时区和时间

爱被打了一巴掌 2023-02-13 03:48 55阅读 0赞

时区文件
CentOS 和 Ubuntu 的时区文件是 /etc/localtime , 但是在 CentOS7 以后 localtime 以及变成了一个链接文件 :

  1. ll /etc/localtime
  2. lrwxrwxrwx. 1 root root 38 Mar 13 2017 /etc/localtime -> ../usr/share/zoneinfo/America/New_York

修改时区
CentOS6 , Ubuntu16 修改方法 :

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

CentOS7 , RHEL7 , Scientific Linux 7 , Oracle Linux 7 :

最好的方法是使用 timedatectl 命令 :

  1. timedatectl set-timezone Asia/Shanghai #其他时区以此类推

或者直接手动创建软链接 :

  1. ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

查看时间

  1. date
  2. Wed Aug 15 10:03:44 CST 2018

修改时间
将系统日期设定成 2009年11月3日下午5点55分55秒 :

  1. date -s "11/03/2009 17:55:55"

将系统时间设定成 下午5点55分55秒 :

  1. date -s 17:55:55

查看硬件时间 (BIOS的) :

  1. hwclock -r

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

  1. hwclock -w

同步时间
yum install ntpdate

  1. ntpdate -u ntp.api.bz

发表评论

表情:
评论列表 (有 0 条评论,55人围观)

还没有评论,来说两句吧...

相关阅读