查看修改Linux時區和時間

來源:互聯網
上載者:User

標籤:

查看/修改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 –show
或
clock –show

  修改Linux硬體時間:
hwclock –set –date
或
clock –set –date

  讓系統時間與硬體時鐘同步,用:
hwclock –hctosys
或
clock –hctosys

  相反地,讓硬體時鐘與系統時間同步:
hwclock –systohc
或
clock –systohc

  讓系統時間每隔十分鐘去同步一下硬體時間。

[[email protected] 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。

查看修改Linux時區和時間

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.