免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 19212 | 回复: 16
打印 上一主题 下一主题

Linux 时间修改 不重启修改时区 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-08-31 19:27 |只看该作者 |正序浏览
Linux 时间修改 不重启修改时区

一、修改linux的时间
root使用date指令:date -s
1、只修改日期,不修改时间,输入:
Linux代码

   1. date -s 2007-08-03  

date -s 2007-08-03


2、只修改时间,输入:
Linux代码

   1. date -s 14:15:00  

date -s 14:15:00


3、同时修改日期时间,注意要加双引号,日期与时间之间有一空格,输入:
Linux代码

   1. date -s "2007-08-03 14:15:00"  

date -s "2007-08-03 14:15:00"



4、修改完后,记得输入:
Linux代码

   1. clock -w   

clock -w


把系统时间写入CMOS


二、修改时区不重启
在root下
1、复制相应的时区文件,替换系统时区文件:
Linux代码

   1. cp /usr/share/zoneinfo/$主时区/$次时区 /etc/localtime  

cp /usr/share/zoneinfo/$主时区/$次时区 /etc/localtime


例如:
Linux代码

   1. cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime  

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime



2、将当前时间和日期写入BIOS,避免重启后失效
Linux代码

   1. hwclock

论坛徽章:
0
17 [报告]
发表于 2012-12-31 09:10 |只看该作者
测试了下,很管用的,信息分享。

论坛徽章:
0
16 [报告]
发表于 2011-12-31 10:32 |只看该作者
   学习了

论坛徽章:
0
15 [报告]
发表于 2011-04-01 16:41 |只看该作者
* 博客园
    * 社区
    * 首页
    * 新随笔
    * 联系
    * 管理
    * 订阅 订阅

随笔- 241  文章- 0  评论- 43
查看/修改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





备注:

      更详细的命令说明请参加man



参考:

      http://www.bitscn.com/linux/system_manage/200604/6898.html

      http://www.hypexr.org/linux_date_time_help.php

      http://www.debianadmin.com/ntp-s ... tion-in-debian.html

      http://www.time.ac.cn/stime.asp

7) Australia
Europe
9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 8
Please select a country.
1) Aaland Islands        1 Greece                35) Norway
2) Albania               19) Guernsey              36) Poland
3) Andorra               20) Hungary               37) Portugal
4) Austria               21) Ireland               3 Romania
5) Belarus               22) Isle of Man           39) Russia
6) Belgium               23) Italy                 40) San Marino
7) Bosnia & Herzegovina  24) Jersey                41) Serbia
Britain (UK)          25) Latvia                42) Slovakia
9) Bulgaria              26) Liechtenstein         43) Slovenia
10) Croatia               27) Lithuania             44) Spain
11) Czech Republic        2 Luxembourg            45) Sweden
12) Denmark               29) Macedonia             46) Switzerland
13) Estonia               30) Malta                 47) Turkey
14) Finland               31) Moldova               4 Ukraine
15) France                32) Monaco                49) Vatican City
16) Germany               33) Montenegro
17) Gibraltar             34) Netherlands
[1这里         Britain (UK)  就是 伦敦  害这个简单问题困扰好久 还是老外旁边说是这个国家名字

论坛徽章:
0
14 [报告]
发表于 2011-04-01 16:40 |只看该作者
设置时区

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
原文地址:http://helenfj.blogbus.com/logs/60894038.html

时间以及时区设置
首先确认使用utc还是local time.
UTC(Universal Time Coordinated)=GMT(Greenwich Mean Time)
Local time 是你手表上的时间

传统的POSIX计算机(Solaris,bsd,unix)使用UTC格式
linux可以处理UTC时间和蹩脚的Windows所使用的local time

到底是使用UTC还是local time可以这样来确定:
如果机器上同时安装有Linux和Windows,建议使用local time
如果机器上只安装有Linux,建议使用utc
确定后编辑/etc/sysconfig/clock, UTC=0 是local time; UTC=1 是UTC(GMT)

1) 使用cat /etc/sysconfig/clock查看当前时区
linux5:~ # cat /etc/sysconfig/clock
## Path:                System/Environment/Clock
## Description:         Information about your timezone and time
## Type:                string
## ServiceRestart:      boot.clock
#
# Set to "-u" if your system clock is set to UTC, and to "--localtime"
# if your clock runs that way.
#
HWCLOCK="-u"

## Type:                string(Europe/Berlin,Europe/London,Europe/Paris)
## ServiceRestart:      boot.clock
#
# Timezone (e.g. CET)
# (this will set /usr/lib/zoneinfo/localtime)
#
TIMEZONE="US/Pacific"
DEFAULT_TIMEZONE="US/Pacific"
linux5:~ #

2) 使用tzselect设置时区,最后结果如下

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
linux5:~ #

3) 复制相应的时区文件,替换系统默认时区
linux5:~ # cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
linux5:~ #

4) 将当前时间写入BIOS永久生效(避免重启后失效)
linux5:~ # hwclock
Tue Jan 29 18:22:59 2008  -0.565688 seconds
linux5:~ #

10. 配置ntp客户端
编辑/etc/ntp.conf,增加一行server 10.30.1.10,其中10.30.1.105就是时钟服务器,如下
linux:/var/log # grep -v \# /etc/ntp.conf

server 10.30.1.105

查看ntp服务的状态
linux:/var/log # /etc/init.d/xntpd  status
Checking for network time protocol daemon (NTPD):                    unused

设置时区以及时间
/usr/sbin/zic -l PRC
/bin/date "+%H:%M:%S - %d-%m-%Y"

写回硬件时钟
/sbin/hwclock --hctosys --localtime
或者写回硬件时钟: hwclock --systohc

在/etc/rc.d/rc5.d创建xntp服务的启动脚本
linux:/etc/rc.d/rc5.d # ln -s ../xntpd S14xntpd
查看ntp时间调整纪录
linux:/var/log # grep ntp messages
Aug 14 07:19:51 linux ntpdate[2837]: step time server 10.30.1.105 offset 2.010174 sec
Aug 14 07:19:51 linux ntpd[2884]: ntpd 4.2.0a@1.1213-r Wed Jun 30 18:37:03 UTC 2004 (1)
Aug 14 07:19:51 linux ntpd[2884]: precision = 1.000 usec
Aug 14 07:19:51 linux ntpd[2884]: Listening on interface wildcard, 0.0.0.0#123
Aug 14 07:19:51 linux ntpd[2884]: Listening on interface wildcard, ::#123
Aug 14 07:19:51 linux ntpd[2884]: Listening on interface lo, 127.0.0.1#123
Aug 14 07:19:51 linux ntpd[2884]: Listening on interface eth0, 10.40.157.66#123
Aug 14 07:19:51 linux ntpd[2884]: kernel time sync status 0040

mmscbill:~ # date
Wed May  7 15:53:10 CST 2008
这里时区设置没有错. PRC是时区的名称,它对应/usr/share/lib/zoneinfo下的PRC时区文件.
CST是Chinese Standard Time的缩写,用在date命令的输出中.它是定义在PRC时区文件中.看
一下/usr/share/lib/zoneinfo/src下的asia文件就知道是怎么回事了.

修改系统时间(bjchenxu,laixi781211,hutuworm)
date -s “2003-04-14 cst”,cst指时区,时间设定用date -s 18:10
修改后执行clock -w 写到CMOS
hwclock --systohc
set the hardware clock to the current system time
分类: RHEL

论坛徽章:
0
13 [报告]
发表于 2011-01-20 18:24 |只看该作者
如果 tzselect 找不到所在国家
cp /usr/share/zoneinfo/$主时区/$次时区 /etc/localtime
ln -sf /usr/share/zoneinfo/GMT /etc/localtime

之后
   1. hwclock

论坛徽章:
0
12 [报告]
发表于 2011-01-20 18:15 |只看该作者
查看时区:
more /etc/sysconfig/clock

设置时区:
tzselect
timeconfig

中国的时区:
Asia/Shanghai

修改时间:
date -s yyyy/MM/dd hh:mm:ss

把时间信息写入CMOS:
hwclock
clock -w

论坛徽章:
0
11 [报告]
发表于 2010-10-28 08:56 |只看该作者
又学到了

论坛徽章:
0
10 [报告]
发表于 2010-10-28 08:39 |只看该作者
非常好,

论坛徽章:
0
9 [报告]
发表于 2010-10-27 15:12 |只看该作者
不执行会跳回来的 是由于 ntp的原因 每30秒一次的网络时间调整

crontab 依赖 crontabs包和 crond服务
因此 crontab 重启需要:
service crond restart
或者
/etc/rc.d/init.d/crond restart

加入开机自动启动:
chkconfig –level 35 crond on
  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP