`
yidongkaifa
  • 浏览: 4048476 次
文章分类
社区版块
存档分类
最新评论

LINUX date modify system time 修改系统时间

 
阅读更多

了解Linux的时钟
由于Linux时钟和Windows时钟从概念的分类、使用到设置都有很大的不同,所以,搞清楚Linux时钟的工作方式与设置操作,不仅对于Linux初学者有着重大意义,而且对于使用Linux服务器的用户来说尤为重要。

Linux时钟的分类

Windows时钟大家可能十分熟悉了,Linux时钟在概念上类似Windows时钟显示当前系统时间,但在时钟分类和设置上却和Windows大相径 庭。和Windows不同的是,Linux将时钟分为系统时钟(System Clock)和硬件(Real Time Clock,简称RTC)时钟两种。系统时间是指当前Linux Kernel中的时钟,而硬件时钟则是主板上由电池供电的那个主板硬件时钟,这个时钟可以在BIOS的“Standard BIOS Feture”项中进行设置。

既然Linux有两个时钟系统,那么大家所使用的Linux默认使用哪种时钟系统呢?会不回出现两种系统时钟冲突的情况呢?这些疑问和担心不无道理。首 先,Linux并没有默认哪个时钟系统。当Linux启动时,硬件时钟会去读取系统时钟的设置,然后系统时钟就会独立于硬件运作。

从Linux启动过程来看,系统时钟和硬件时钟不会发生冲突,但Linux中的所有命令(包括函数)都是采用的系统时钟设置。不仅如此,系统时钟和硬件时 钟还可以采用异步方式,见图1所示,即系统时间和硬件时间可以不同。这样做的好处对于普通用户意义不大,但对于Linux网络管理员却有很大的用处。例 如,要将一个很大的网络中(跨越若干时区)的服务器同步,假如位于美国纽约的Linux服务器和北京的Linux服务器,其中一台服务器无须改变硬件时钟 而只需临时设置一个系统时间,如要将北京服务器上的时间设置为纽约时间,两台服务器完成文件的同步后,再与原来的时钟同步一下即可。这样系统和硬件时钟就 提供了更为灵活的操作。

设置Linux的时钟

在Linux中,用于时钟查看和设置的命令主要有date、hwclock和clock。其中,clock和hwclock用法相近,只不过clock命 令除了支持x86硬件体系外,还支持Alpha硬件体系。由于目前绝大多数用户使用x86硬件体系,所以可以视这两个命令为一个命令来学习。

1.在虚拟终端中使用date命令来查看和设置系统时间
查看系统时钟的操作:
# date

设置系统时钟的操作:
# date 091713272003.30

通用的设置格式:
# date 月日时分年.秒

2.使用hwclock或clock命令查看和设置硬件时钟
查看硬件时钟的操作:
# hwclock –show 或
# clock –show
2003年09月17日 星期三 13时24分11秒 -0.482735 seconds

设置硬件时钟的操作:
# hwclock –set –date=”09/17/2003 13:26:00″

或者
# clock –set –date=”09/17/2003 13:26:00″

通用的设置格式:hwclock/clock –set –date=“月/日/年 时:分:秒”。

3.同步系统时钟和硬件时钟

Linux系统(笔者使用的是Red Hat 8.0,其它系统没有做过实验)默认重启后,硬件时钟和系统时钟同步。如果不大方便重新启动的话(服务器通常很少重启),使用clock或hwclock命令来同步系统时钟和硬件时钟。

硬件时钟与系统时钟同步:
# hwclock –hctosys

或者
# clock –hctosys

上面命令中,–hctosys表示Hardware Clock to SYStem clock。

系统时钟和硬件时钟同步:
# hwclock –systohc

或者
# clock –systohc

使用图形化系统设置工具设置时间

对于初学者来,笔者推荐使用图形化的时钟设置工具,如Red Hat 8.0中的日期与时间设置工具,可以在虚拟终端中键“redhat-config-time”命令,或者选择“K选单/系统设置/日期与时间”来启动日期 时间设置工具。使用该工具不必考虑系统时间和硬件时间,只需从该对话框中设置日期时间,可同时设置、修改系统时钟和硬件时钟。

Internet同步时钟设置

在Windows XP日期与时间设置中有一项与Internet同步的功能,有了这项功能只要上网便可得到十分准确的时间。Red Hat 8.0也提供了这样的功能,在日期与时间设置工具对话框中的下部,有一个“启用网络时间协议”的选项,将该项选中就可以使用网络时间协议来同步Linux 系统时钟。选中该项后,其下面的服务器下拉列表框就变为可用状态,可从中选择一个时间服务器作为远程时间服务器。然后单击确定按钮,便可连接所设定的时间 服务器,并与之同步时间。

转自http://gnu.shslzx.cn/?p=288

分享到:
评论

相关推荐

    Linux Essentials for Cybersecurity

    Troubleshoot common Linux security problems, one step at a time Protect user and group accounts with Pluggable Authentication Modules (PAM), SELinux, passwords, and policies Safeguard files and ...

    8-07-14_MegaCLI for linux_windows

    包含如下操作系统版本 FreeBSD Linux Solaris Windows 分别对应如下目录 MegaCLI for DOS MegaCLI for Linux MegaCLI for Solaris MegaCLI for FreeBSD MegaCLI for Windows ********************************...

    ELDK使用与开发手册

    date – get/set/reset date & time dhcp – invoke DHCP client to obtain IP/boot params dtt – Digital Thermometer and Thermostat echo – echo args to console eeprom – EEPROM sub-system erase – erase ...

    UE(官方下载)

    Parsing XML can be a time-consuming task, especially when large amounts of data are involved. As of v15.10, UltraEdit provides you with a the XML Window for the purpose of parsing ...

    Universal-USB-Installer

    安装linux工具源码 (UUI) Universal USB Installer ?009-2012 Lance http://www.pendrivelinux.com This Open Source tool falls under the GNU General Public License Version 2 Source Code is made available at...

    WizFlow网页编辑

    operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a ...

    hibernate-shards.jar

    operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a ...

    计算机网络第六版答案

    28. Trudy can pretend to be Bob to Alice (and vice-versa) and partially or completely modify the message(s) being sent from Bob to Alice. For example, she can easily change the phrase “Alice, I owe ...

    apktool documentation

    Every Apktool release contains internally the most up to date AOSP framework at the time of the release. This allows you to decode and build most apks without a problem. However, manufacturers add ...

    Bochs - The cross platform IA-32 (x86) emulator

    attributes, 1.44 MB floppy support, set file modification date/time - converted the complete hdimage stuff to the new 'hdimage' plugin - new hdimage method get_capabilities() that can return ...

    uboott移植实验手册及技术文档

    4、交叉编译器 arm-softfloat-linux-gnu-gcc-3.4.5 【实验步骤】 一、建立自己的平台类型 (1)解压文件 #tar jxvf u-boot-1.3.1.tar.bz2 (2)进入 U-Boot源码目录 #cd u-boot-1.3.1 (3)创建自己的开发板...

Global site tag (gtag.js) - Google Analytics