Linux modification Time Daquan

Source: Internet
Author: User
Tags time zones set time

We generally use the "date-s" command to modify the system time. For example, the command to set the system time to June 10, 1996 is as follows.

#date-S 06/10/96
The command to set the system time to 1:12 P.M. 0 seconds is as follows.
#date-S 13:12:00

Note that this is the system time and Linux is maintained by the operating system.

When the system starts, the Linux operating system reads the time from the CMOS into the system time variable, and the later modification time is realized by modifying the system time. To keep the system time consistent with the CMOS time, Linux writes the system time to CMOS at every time. Since this synchronization takes place at intervals (about 11 minutes), if the machine is re-started immediately after we execute the DATE-S, the modification time may not be written to the CMOS, which is the cause of the problem. You can execute the following command if you want to make sure that the changes take effect.

#hwclock-W
This command forces the system time to be written to the CMOS
-------------------------------------------------------------------------------
Since Linux clocks and Windows clocks vary greatly from concept classification and usage to setup, figuring out how the Linux clock works and how to set it is important not only for Linux beginners, but also for users who use Linux servers.

Classification of Linux Clocks

Windows clock Everyone may be familiar with the idea that the Linux clock is conceptually similar to the Windows clock that displays the current system time, but differs from windows in terms of clock classification and setup. Unlike Windows, Linux divides clocks into systems clocks (System clock) and hardware (Real time clock, or RTC) clocks. System time refers to the clock in the current Linux kernel, while the hardware clock is the battery-powered motherboard hardware clock on the motherboard, which can be set in the BIOS "standard BIOS feture" entry.

Since Linux has two clock systems, what kind of clock system do you use for Linux by default? Will there be a case of two system clock conflicts? These doubts and fears are justified. First, Linux does not have a default clock system. When Linux starts, the hardware clock reads the settings of the system clock, and the system clock is independent of the hardware.

From the Linux boot process, there is no conflict between the system clock and the hardware clock, but all commands (including functions) in Linux are the system clock settings used. Furthermore, the system clock and hardware clock can also be asynchronous, as shown in Figure 1, where system time and hardware time can be different. The benefits of doing so are of little significance to the average user, but are of great use to Linux network administrators. For example, to synchronize a server in a large network (spanning several time zones), if a Linux server in New York and a Linux server in Beijing, one server does not need to change the hardware clock but only temporarily set a system time, such as to set the time on the Beijing server to New York time, Two servers to complete the synchronization of the file, and then sync with the original clock. This allows for more flexible operation of the system and hardware clocks.

Set the clock for Linux

In Linux, the commands used for clock viewing and setting are mainly date, hwclock, and clock. Among them, clock and hwclock usage similar, but clock command in addition to support x86 hardware system, but also support the Alpha hardware system. Since most users currently use the x86 hardware system, these two commands can be considered as a command to learn.

1. Use the date command in the virtual terminal to view and set the system time

To view the operation of the system clock:

# date

To set the operation of the system clock:

# date 111309272017.30

   Date MMDDHHMMYYYY.SS

Common formatting:

# Date Month day year. seconds

2. Use the Hwclock or clock command to view and set the hardware clock

To view the operation of the hardware clock:

# Hwclock--show or

# clock--show

  November 13, 2017 Monday 09:54 44 sec -0.672850 seconds



To set the hardware clock operation:

# Hwclock--set--date= "11/13/2017 09:26:00"

Or

# clock--set--date= "11/13/2017 09:26:00"

Common formatting: Hwclock/clock--set--date= "month/day/year: minutes: Seconds".

3. Synchronizing the system clock and hardware clock

Linux systems (the author uses Red Hat 8.0, other systems have not done experiments) the hardware clock is synchronized with the system clock after the default reboot. If it is not easy to reboot (the server usually restarts infrequently), use the clock or the Hwclock command to synchronize the system clock and the hardware clock.

The hardware clock is synchronized with the system clock:

# Hwclock--hctosys

Or

# clock--hctosys

In the above command,--hctosys represents hardware clock to SYStem clock.

system clock and Hardware clock synchronization:

# Hwclock--SYSTOHC

Or

# clock--SYSTOHC

Set time using the Graphical System Setup tool

For beginners, the author recommends using a graphical clock setup tool, such as the date and time Settings tool in red Hat 8.0, to "redhat-config-time" commands in the virtual terminal, or to select "K Menu/System settings/Date and time" to start the DateTime setting tool. The tool does not have to consider the system time and hardware time, just set the date time from this dialog box, you can set up, modify the system clock and hardware clock.

Internet Sync Clock settings

There is a feature that synchronizes with the Internet in Windows XP date and time settings, and with this feature you can get very accurate time on the Internet. Red Hat 8.0 also provides a feature that, in the lower part of the date and Time Setup Tool dialog box, has an option to "Enable Network Time Protocol", which can be selected to synchronize the Linux system clock with the network time protocol. When the item is selected, the following server drop-down list box becomes available, from which you can select a time server as a remote time server. Then click the OK button to connect and synchronize time with the set time server.

Linux modification Time Daquan

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.