Time-related commands in CentOS

Source: Internet
Author: User
Tags sunrise time

Time-related commands in CentOS

Time is the most basic part in any system and is indispensable. This document describes the time-related commands in the CentOS system.

Basic Concepts

Hardware Clock (Hardware Clock)
Hardware clock, also known as RealTimeClock, BIOS clock, or CMOS clock. It is an actual hardware device located on the machine motherboard and is generally maintained by a battery. Therefore, even if the machine is shut down, it will keep recording the current time, which is generally not very accurate.

System Time)
System time refers to the time in the operating system. It is driven by the hardware timer after the system is powered on. Linux uses the timer signal to increase the time count. This timer is very accurate with a small error.

When a Linux system is started, it first reads the current time from the hardware clock to initialize the system time count, and then increments it according to the timer interruption, instead of relying on the hardware clock.

Time zone)
The sunrise time varies from country to country, but the time of sunrise is called six o'clock locally. At the same time, the clock and pointer positions in different countries are different. The emergence of the time zone. UTC is the world standard, and other time zones are increased or decreased based on this. For example, China's Beijing time is eight hours earlier than the world time.

The hardware clock generally does not record the time zone information, but usually only the local time. The concept of time zone must be taken into account for system time. Otherwise, the time cannot be unified when computers in different time zones exchange information. This is critical to many software systems, such as version management systems that rely heavily on time labels. The Linux kernel stores the information about the current time zone. The Linux file system depends on the information about this time zone.

Common command 1: View and set the current BIOS time
[Root @ centos192 smstong] # hwclock-r # Read the hardware clock from 12: 30: 46 seconds-0.891230 seconds [root @ centos192 smstong] # hwclock -- set -- date = "06/03/2015 16:45:05 "# Set the hardware clock
2. View and set the current operating system time
[Root @ centos192 smstong] # date # view the current system time on Wednesday, June 03, 2015 19:37:55 CST [root @ centos192 smstong] # date-s 10:00:00 # set the system time on Wednesday, June 03, 2015 10:00:00 CST
3. hardware clock interaction with system time
[Root @ centos192 smstong] # hwclock -- hctosys # set the system time with the hardware clock [root @ centos192 smstong] # hwclock -- systohc # Set the hardware clock with the system time
4. View and set the time zone of the current system
[Root @ centos192 smstong] # date-R # view the current system time Wed with time zone information, 03 Jun 2015 19:45:37 + 0800 [root @ centos192 smstong] # export TZ = 'America/Havana '# set the time zone to Cuba time [root @ centos192 smstong] # date-R # You can see the time zone is-0400Wed, 03 Jun 2015 07:49:49-0400

To set the time zone permanently, you can add export TZ = 'America/Havana 'in the/etc/profile configuration file '. In this way, the time zone is automatically set after the machine is restarted.

Note that linux kernels and applications use different time zones, although they should be the same. The application first determines the time zone based on the TZ environment variables. If TZ Is not set, the kernel settings are used. The kernel sets the time zone according to the/etc/sysconfig/clock file.* (This is my guess. please correct me )*

5. Network-based school hours
As we have mentioned above, the hardware clock is often inaccurate. Although the system clock is accurate, it still cannot meet the high-precision time requirements. The best way is to read the correct time from a dedicated time server through the NTP protocol, and then correct the system time and hardware clock.
[Root @ centos192 smstong] # ntpdate-u s1a.time.edu.cn # system time correction during NTP calibration 3 Jun 19:56:42 ntpdate [21550]: adjust time server 202.112.10.60 offset 0.000163 sec [root @ centos192 smstong] # hwclock-w # then set the hardware clock based on the corrected system time

For a server that runs for a long time, you need to write the school-time command as a script and use crond to automatically and periodically execute it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.