The time of the Linux system is sometimes inaccurate. Inaccurate time will cause errors in the time in the log file, so the exact time is very important, then How do I change the time of my Linux system? The following small series introduces you to the steps to change the Linux system time and date using the command line.
Question: On Linux, how can I change the date and time via the command line?
Keeping date and time synchronized on Linux systems is an important responsibility for every Linux user and system administrator. Many programs rely on accurate time information to work properly. In addition, inaccurate dates and times can make timestamps in log files meaningless, reducing their role in system inspection and troubleshooting. For production systems, precise dates and times are even more important. For example, in a retail company, all products must be accurately counted (and stored in a database server) at all times to allow the finance department to calculate daily and weekly, monthly, and yearly expenses and revenue.
We must note that there are two kinds of clocks on a Linux machine: the software clock maintained by the kernel (also known as the system clock) and the (battery-powered) hardware clock that records the time after the machine is turned off. At startup, the kernel synchronizes the system clock with the hardware clock. After that, the two clocks operate independently of each other.
Method One: Date command
In Linux, you can change the date and time of the system by the date command:
# date --set = & lsquo ;NEW_DATE’
where NEW_DATE is a date string such as "Sun, 28 Sep 2014 16:21:42" or ""2014-09-29 16:21:42”
Date formats can also be manually specified for more accurate results:
# date +FORMAT --set=‘NEW_DATE’
For example:
# date + & rsquo;% Y% m% d% H% m & rsquo; --set = & lsquo; 20140928 1518 & rsquo;
you can also use the opposite manner to increase or decrease certain number of days, Weeks, months and seconds, minutes, hours. You can also put the date and time parameters into a single command.
# date --set=‘+5 minutes’# date --set=‘-2 weeks’# date --set=‘+3 months’# date --set=‘ -3 months +2 weeks -5 minutes & rsquo;
Finally, the hardware clock to the current system clock:
# hwclock --systohc
run hwclock - The purpose of -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 this case, the hwclock command synchronizes the two clocks. Otherwise, the time after the restart will be wrong, because the hardware clock will remember the time when the power is turned off. However, this does not apply to virtual machines because the virtual machine does not have access to the hardware clock.
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 a public NTP server via NTP.
You can install ntpdate using the following command:
On Debian and Debian-based distributions:
# aptitude install ntpdate
Based on Ret On the distribution of Hat:
# yum install ntpdate
Synchronizing the system clock with NTP:
# ntpdate -u "NTP server name or IP"# hwclock --systohc
in addition to one-time use ntpdate to synchronize the clock, you can also use the NTP daemon (ntpd), it will always run in the background, continually adjust the system clock via NTP.
The above is a way to change the date and time of the Linux system using the command line. If you want to use the command line to modify the Linux system, try the method steps described above.
mono is a cross-platform ·NET runtime environment developed by Novell. It ca
Linux users are certainly no stranger to the CentOS server, but how to initialize the CentOS server
The network management of Red Hat Enterprise Linux 7 and CentOS 7 is actually the management of Netw
If you want to make RPM package under Linux system, you can use FPM tool to complete it. The FPM too
Solve the problem of installing Linux prompt Boot Efi does not have space to set up
FreeBSD steps to load iso files through virtual CD-ROMs
How to use the df command to view Linux disk space?
Usage of Linux global variable jiffies
Steps to Mount an LVM Partition on a Linux System
How to install and set up MQ in Linux
The specific usage of the tee command in Linux system
Summary of how to completely delete Linux files
Linux terminal prompt path length modification method
The basic process of setting serial port properties in Linux system
Linux dual-system computer reinstalled Windows after entering Red Flag Linux
Win7 system IE browser prompts website restore error reason and solution graphic tutorial
A good way to keep the Windows desktop clean and tidy
Win8 comes with Office office software
Linux Network Operation Command Encyclopedia
Win7 copy file error "cyclic redundancy check" response measures
Win10 edge set home page method tutorial
How to open ODBC program in Win7 system? How to open ODBC program in Win7
Introducing the rich and practical functions of Win7 calculator
Win10 system to create a local account where to create a local account specific steps