標籤:linux date
Linux系統的時間管理
1 查看系統時間和日期 :date
[[email protected] Desktop]# date Tue Jun 2 05:25:05 EDT 2015
2查看硬體時間:hwclock --show | -r
[[email protected] Desktop]# hwclock Tue 02 Jun 2015 05:40:30 AM EDT -0.272377 seconds
3 修改系統時間使用的命令:
修改系統時間:
[[email protected] named]# date -s "6/1/2015 18:00:00" #設定為6月/1日/2015年 時:分:秒Mon Jun 1 18:00:00 EDT 2015[[email protected] named]# date -s "11:11:11 2011-10-3" #這樣也行Mon Oct 3 11:11:11 CST 2011
修改系統硬體時間:
[[email protected] Desktop]# hwclock --set --date="06/18/14 14:55" [[email protected] Desktop]# hwclock -r ##相當於hwclock --showWed 18 Jun 2014 02:55:22 PM EDT -0.569262 seconds
4 將當前系統的時間和日期寫入BIOS,避免重啟後失效 : hwclock -w
[[email protected] Desktop]# hwclock -w
注意:
hwclock
##將系統時間設定為當前硬體的時間
-s, --hctosys set the system time from the hardware clock
##將硬體的時間設定為當前系統的時間
-w, --systohc set the hardware clock from the current system time
5 時區的更改:tzselect
tzselect 只是提示我們去選擇時區,實際上不會生效,但我們可以根據提示去操作。
[[email protected] Desktop]# tzselect Please identify a location so that time zone rules can be set correctly.Please select a continent or ocean. 1) Africa 2) Americas 3) Antarctica 4) Arctic Ocean 5) Asia 6) Atlantic Ocean 7) Australia 8) Europe 9) Indian Ocean10) Pacific Ocean11) none - I want to specify the time zone using the Posix TZ format.#? 5Please select a country. 1) Afghanistan 18) Israel 35) Palestine 2) Armenia 19) Japan 36) Philippines 3) Azerbaijan 20) Jordan 37) Qatar 4) Bahrain 21) Kazakhstan 38) Russia 5) Bangladesh 22) Korea (North) 39) Saudi Arabia 6) Bhutan 23) Korea (South) 40) Singapore 7) Brunei 24) Kuwait 41) Sri Lanka 8) Cambodia 25) Kyrgyzstan 42) Syria 9) China 26) Laos 43) Taiwan10) Cyprus 27) Lebanon 44) Tajikistan11) East Timor 28) Macau 45) Thailand12) Georgia 29) Malaysia 46) Turkmenistan13) Hong Kong 30) Mongolia 47) United Arab Emirates14) India 31) Myanmar (Burma) 48) Uzbekistan15) Indonesia 32) Nepal 49) Vietnam16) Iran 33) Oman 50) Yemen17) Iraq 34) Pakistan#? 9Please select one of the following time zone regions.1) east China - Beijing, Guangdong, Shanghai, etc.2) Heilongjiang (except Mohe), Jilin3) central China - Sichuan, Yunnan, Guangxi, Shaanxi, Guizhou, etc.4) most of Tibet & Xinjiang5) west Tibet & Xinjiang#? 1The following information has been given:Chinaeast China - Beijing, Guangdong, Shanghai, etc.Therefore TZ=‘Asia/Shanghai‘ will be used.Local time is now:Wed Jun 3 09:31:59 CST 2015.Universal Time is now:Wed Jun 3 01:31:59 UTC 2015.Is the above information OK?1) Yes2) No#? 1 ##以下是一個實際生效的提示You can make this change permanent for yourself by appending the lineTZ=‘Asia/Shanghai‘; export TZto the file ‘.profile‘ in your home directory; then log out and log in again.Here is that TZ value again, this time on standard output so that youcan use the /usr/bin/tzselect command in shell scripts:Asia/Shanghai
根據後面的提示,需要將 TZ=‘Asia/Shanghai‘; export TZ 這一行寫入到.profile設定檔中,不過我習慣寫在.bashrc檔案中。
[[email protected] ~]# vim /root/.bash_profile ##編輯目前使用者的bash環境檔案[[email protected] ~]# cat /root/.bash_profile# .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then. ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/binexport PATHTZ=‘Asia/Shanghai‘; export TZ ##將時區更改的語句 放到這裡
建議把時區設定寫在/etc/bashrc這個檔案中,全域生效。
查看當前的時區:
[[email protected] Desktop]# date -RTue, 02 Jun 2015 22:09:31 -0400
重新整理重讀一下.bash_profile
[[email protected] Desktop]# date -RTue, 02 Jun 2015 22:14:49 -0400[[email protected] Desktop]# source /root/.bash_profile [[email protected] Desktop]# date -R
Wed, 03 Jun 2015 10:15:10 +0800 ##時區已更改為北京時區
另一種方法:直接修改設定檔
時區的設定檔:/etc/localtime
所有時區檔案的存放路徑:/usr/share/zoneinfo
亞洲時區:/usr/share/zoneinfo/Asia
選擇上海時區:/usr/share/zoneinfo/Asia/Shanghai
將上海時區的檔案軟體連結到時區的設定檔/etc/localtime
[[email protected] /]# ln -s /usr/share/zoneinfo/Asi a/Shanghai /etc/localtime
重啟之後查看date -R
圖形介面:
redhat 6以下:system-config-time
redhat 7:system-config-date
本文出自 “天道酬勤” 部落格,請務必保留此出處http://luzhi1024.blog.51cto.com/8845546/1657804
Linux系統的時間管理