1. 程式人生 > >Linux修改時區&時間

Linux修改時區&時間

時區檔案

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