码迷,mamicode.com
首页 > 系统相关 > 详细

Linux系统的时间管理

时间:2015-06-03 13:55:15      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:linux   date   

Linux系统的时间管理

1 查看系统时间和日期 :date 

[root@desktop0 Desktop]# date 
Tue Jun  2 05:25:05 EDT 2015


2查看硬件时间:hwclock --show | -r

[root@desktop0 Desktop]# hwclock 
Tue 02 Jun 2015 05:40:30 AM EDT  -0.272377 seconds


3 修改系统时间使用的命令:

修改系统时间:

[root@classroom named]# date -s "6/1/2015 18:00:00" #设置为6月/1日/2015年 时:分:秒
Mon Jun  1 18:00:00 EDT 2015
[root@classroom named]# date -s "11:11:11 2011-10-3" #这样也行
Mon Oct  3 11:11:11 CST 2011

修改系统硬件时间:

[root@desktop0 Desktop]# hwclock --set --date="06/18/14 14:55" 
[root@desktop0 Desktop]# hwclock -r   ##相当于hwclock --show
Wed 18 Jun 2014 02:55:22 PM EDT  -0.569262 seconds

4 将当前系统的时间和日期写入BIOS,避免重启后失效 : hwclock -w

[root@desktop0 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 只是提示我们去选择时区,实际上不会生效,但我们可以根据提示去操作。

[root@desktop0 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 Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 5
Please 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) Taiwan
10) Cyprus  27) Lebanon    44) Tajikistan
11) East Timor  28) Macau    45) Thailand
12) Georgia  29) Malaysia    46) Turkmenistan
13) Hong Kong  30) Mongolia    47) United Arab Emirates
14) India  31) Myanmar (Burma)    48) Uzbekistan
15) Indonesia  32) Nepal    49) Vietnam
16) Iran  33) Oman    50) Yemen
17) Iraq  34) Pakistan
#? 9
Please select one of the following time zone regions.
1) east China - Beijing, Guangdong, Shanghai, etc.
2) Heilongjiang (except Mohe), Jilin
3) central China - Sichuan, Yunnan, Guangxi, Shaanxi, Guizhou, etc.
4) most of Tibet & Xinjiang
5) west Tibet & Xinjiang
#? 1
The following information has been given:
China
east 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) Yes
2) No
#? 1
   ##以下是一个实际生效的提示
You can make this change permanent for yourself by appending the line
TZ=‘Asia/Shanghai‘; export TZ
to 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 you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai

根据后面的提示,需要将 TZ=‘Asia/Shanghai‘; export TZ 这一行写入到.profile配置文件中,不过我习惯写在.bashrc文件中。

[root@desktop0 ~]# vim /root/.bash_profile ##编辑当前用户的bash环境文件
[root@desktop0 ~]# cat /root/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
TZ=‘Asia/Shanghai‘; export TZ   ##将时区更改的语句 放到这里

建议把时区设置写在/etc/bashrc这个文件中,全局生效。


查看当前的时区:

[root@desktop0 Desktop]# date -R
Tue, 02 Jun 2015 22:09:31 -0400

刷新重读一下.bash_profile

[root@desktop0 Desktop]# date -R
Tue, 02 Jun 2015 22:14:49 -0400
[root@desktop0 Desktop]# source /root/.bash_profile 
[root@desktop0 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

[root@desktop0 /]# 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系统的时间管理

标签:linux   date   

原文地址:http://luzhi1024.blog.51cto.com/8845546/1657804

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!