CentOS時間的查看與修改

來源:互聯網
上載者:User

CentOS時間的查看與修改

1、查看、修改Linux時區與時間


一、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

二、linux時間的查看與修改


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

[html]view plaincopyprint?
  1. hwclock–hctosys
  2. #或
  3. clock–hctosys


修改Linux系統時間:
date -s (後面跟時間)

查看Linux硬體時間:

Java代碼
[html]view plaincopyprint?
  1. hwclock
  2. #或
  3. clock
  4. #或
  5. hwclock–show
  6. #或
  7. clock–show

修改Linux硬體時間:

C代碼

[csharp]view plaincopyprint?
  1. hwclock–set–date
  2. #或
  3. clock–set–date
讓系統時間與硬體時鐘同步,用:

C代碼

[html]view plaincopyprint?
  1. hwclock–hctosys
  2. #或
  3. clock–hctosys
相反地,讓硬體時鐘與系統時間同步:

C代碼

[html]view plaincopyprint?
  1. hwclock–systohc
  2. #或
  3. clock–systohc

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

C代碼
[html]view plaincopyprint?
  1. [hqw@localhostroot]$vi/etc/crontab
  2. SHELL=/bin/bash
  3. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  4. MAILTO=root
  5. HOME=/
  6. #run-parts
  7. 01****rootrun-parts/etc/cron.hourly
  8. 024***rootrun-parts/etc/cron.daily
  9. 224**0rootrun-parts/etc/cron.weekly
  10. 4241**rootrun-parts/etc/cron.monthly
  11. */10****roothwclock--hctosys#加入此行,每隔10分鐘執行一次hwclock--hctosys

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.