next up previous contents index
Next: When the clock is Up: Keeping Time Previous: The hardware and software

显示和设置时钟

在Debian系统中,系统时区由符号连接/etc/localtime 决定。 连接指向描述本地时区的时区数据文件。时区数据文件存在/usr/lib/zoneinfo 中。 其他Linux distributions可能不同。

用户可以用设置TZ环境变量来改变他的私人时区。如果不设置,就假定是系统时区。 TZ变量的语法在tzset (3)man页中说明。

date 命令显示当前日期和时间。 gif 例如:

$ date
Sun Jul 14 21:53:41 EET DST 1996
$
That time is Sunday, 14th of July, 1996, at about ten before ten at the evening, in the time zone called ``EET DST'' (which might be East European Daylight Savings Time). date 也可用于显示通用时间:
$ date -u
Sun Jul 14 18:53:42 UTC 1996
$
date 也可用于设置核心的软件始终:
# date 07142157
Sun Jul 14 21:57:00 EET DST 1996
# date
Sun Jul 14 21:57:02 EET DST 1996
#
更详细的见date man页--syntax is a bit arcane. 只有root能设置时间。虽然每个用户可以有自己的时区,但 时钟对每个人都是一样的。

date 只显示或设置软件时钟。 clock 命令同步硬件和软件时钟。 用于系统启动时读取硬件时钟和设置软件时钟。如果两个时钟都需要设置, 则先用date 设置软件时钟,然后用clock -w 设置硬件时钟。

clock -u告诉它硬件时钟是通用时间。 必须正确使用-u选项。否则计算机将困惑到底是什么时间。

时钟必须小心改变。Unix系统的许多部分要求时钟工作正常。例如, cron 守侯程序周期地运行命令。 如果改变时钟,它可能迷惑它是否该运行命令。 On one early Unix system, someone set the clock twenty years into the future, and cron  wanted to run all the periodic commands for twenty years all at once. 现在版本的cron 可以正确处理, 但仍然要小心。大的前后跳跃比小的更危险。


next up previous contents index
Next: When the clock is Up: Keeping Time Previous: The hardware and software

Linux学院
RedhatCentOSSuse LinuxDebianUbuntu
Sun Jun 29 13:31:22 EEST 1997
《Linux命令大全》 | 《Linux函数调用大全》 | 《Linux系统管理员手册》 | 中国存储网