In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how the Linux system has used the command to change the date and time", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how the Linux system has used commands to change the date and time.
Question: on Linux, how do I change the date and time from the command line?
Keeping date and time synchronized in Linux system is an important responsibility of every Linux user and system administrator. Many programs rely on accurate time information to work properly. In addition, imprecise dates and times make timestamps in log files meaningless, weakening their role in system inspection and maintenance. For the production system, the exact date and time is even more important. For example, in a retail company, all products must be counted accurately (and stored in a database server) at all times so that the financial department can calculate daily and weekly, monthly, and annual expenditure and income.
We must note that there are two types of clocks on Linux machines: a software clock (also known as a system clock) maintained by the kernel and a (battery-powered) hardware clock that records time after the machine is turned off. At startup, the kernel synchronizes the system clock with the hardware clock. After that, the two clocks run independently.
Method 1: Date command
In Linux, you can change the date and time of the system with the date command:
# date-set='NEW_DATE'
Where NEW_DATE is a date string in a readable format such as Sun, 28 Sep 2014 16:21:42 or 2014-09-29 16:21:42.
The date format can also be manually specified for more accurate results:
# date + FORMAT-- set='NEW_DATE'
For example:
# date +'% Y%m%d% H% m'--set='20140928 1518'
You can also increase or decrease a certain number of days, weeks, months and seconds, minutes, and hours in a relative way. You can also put the date and time parameters in a command.
# date-- set='+5 minutes'# date-- set='-2 weeks'# date-- set='+3 months'# date-- set='-3 months + 2 weeks-5 minutes'
Finally, set the hardware clock to the current system clock:
# hwclock-systohc
The purpose of running hwclock-systohc is to synchronize the hardware clock with the software clock, which corrects the system drift of the hardware clock (that is, the clock goes faster or slower at a certain speed).
On the other hand, if the hardware clock is correct, but the system clock is incorrect, you can correct it with the following command:
# hwclock-hctosys
In both cases, the hwclock command synchronizes the two clocks. Otherwise, the time after restart will be wrong, because the hardware clock will remember the time when the power is off. However, this does not apply to virtual machines because virtual machines do not have access to hardware clocks.
Method 2: NTP
Another way to keep the system date and time accurate is to use NTP (Network time Protocol). On Linux, the ntpdate command synchronizes the system clock with the public NTP server through NTP.
You can install ntpdate using the following command:
On Debian and Debian-based distributions:
# aptitude install ntpdate
On Ret Hat-based distributions:
# yum install ntpdate
Use NTP to synchronize the system clock:
# ntpdate-u # hwclock-- systohc
In addition to using ntpdate once to synchronize the clock, you can also use the NTP daemon (ntpd).
At this point, I believe you have a deeper understanding of "how the Linux system used the command to change the date and time". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.