Linux修改时区&时间

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tojohnonly/article/details/81699408

时区文件

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

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


修改时区

CentOS6 , Ubuntu16 修改方法 :

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

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

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

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

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

# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime


查看时间

# date
Wed Aug 15 10:03:44 CST 2018


修改时间

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

# date -s "11/03/2009 17:55:55"

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

# date -s 17:55:55

查看硬件时间 (BIOS的) :

# hwclock -r

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

# hwclock -w


同步时间

yum install ntpdate

# ntpdate -u ntp.api.bz

作者 Github : tojohnonly , 博客 : EnskDeCode

猜你喜欢

转载自blog.csdn.net/tojohnonly/article/details/81699408