System time under Linux

Source: Internet
Author: User

The Linux clock is divided into the system clock and the hardware (Real time clock, or RTC) clock. The system clock is the clock in the current Linux kernel, and the hardware clock is a battery-powered clock on the motherboard that can be set in the BIOS. When Linux starts, the hardware clock reads the settings of the system clock, and the system clock is independent of the hardware.

All commands in Linux, including functions, are the system clock settings used. In Linux, the commands used for clock viewing and setting are mainly date, hwclock, and clock. Among them, clock and hwclock usage similar, only one on the line, but clock command in addition to support x86 hardware system, but also support the Alpha hardware system.

1. Date

View system time

# date + "%y-%m-%d%T"

Setting the system time

# date--set "07/07/06 10:19" (Month/day/year: minutes: seconds)


2, Hwclock/clock

Viewing hardware time

# Hwclock--show

or # clock--show

Set Hardware time

# Hwclock--set--date= "07/07/06 10:19" (Month/day/year: minutes: seconds)

or # clock--set--date= "07/07/06 10:19" (Month/day/year: minutes: seconds)


3. Synchronization of hardware time and system time

According to the foregoing, reboot the system, hardware time will read the system time, to achieve synchronization, but do not restart, you need to use the Hwclock or clock command to achieve synchronization.

Hardware clock synchronization with system clock: # Hwclock--hctosys (HC stands for hardware time, SYS stands for system time) or # clock--hctosys

system clock and Hardware clock sync: # hwclock--SYSTOHC or # clock--SYSTOHC


4, the time zone settings

# Tzselect

Please identify a, so, time zone rules can be set correctly. Please select a continent or ocean. 1) Africa 2) Americas 3) Antarctica 4) Arctic Ocean 5) Asia 6) Atlantic Ocean 7) Australia 8) Europe 9) Indian Ocean10) Pa Cific Ocean11) None-i want to specify the time zone using the Posix TZ format.#? Input 5, Asia

Please select a country. 1) Afghanistan            ) Israel               &NBSP ; Palestine 2) Armenia                  19) Japan       &NBS P         Philippines 3) Azerbaijan              20) Jordan &nbsp ;              37) Qatar 4) Bahrain               &NBS P   Kazakhstan        ) Russia 5) Bangladesh            ) K Orea (north)       Saudi Arabia 6) Bhutan                 &NBSP ; Korea (south)      40) Singapore 7) Brunei                 &NBS P  24) Kuwait                 (Cambodia) Sri Lanka 8)           25) Kyrgyzstan           Syria 9) China   &NBSP ;                 ( ) Laos               nbsp TAIWAN10) Cyprus                   Lebanon       &NBSP ;     Tajikistan11) East Timor              28) Macau                45) Thailand12) Georgia                  29 ) Malaysia             Turkmenistan13) Hong Kong           &NBS P   Mongolia            ) Arab Emirates14) India       &NBSP ;               Myanmar (Burma) Uzbekistan15) Indonesia       &NBS P        32) Nepal                  49)   VIETNAM16) Iran &N Bsp                      33) Oman           &N Bsp      50) YEMEN17) Iraq                        3 4) pakistan#? Input 9, China

Please select one of the following time zone Regions.1) east China-beijing, Guangdong, Shanghai, Etc.2) Heilongjiang3) c Entral China-gansu, Guizhou, Sichuan, Yunnan, Etc.4) Tibet & most of Xinjiang Uyghur5) southwest Xinjiang uyghur#? Input 1, GMT

The following information has been given:

China East China-beijing, Guangdong, Shanghai, etc.

Therefore tz= "Asia/shanghai" would be used. Local time is Now:fri Jul 7 10:32:18 CST 2006.Universal time is Now:fri Jul 7 02:32:18 UTC 2006.Is the above inf Ormation ok?1) Yes2) no#? Enter 1 to confirm


If you do not use the Tzselect command, you can modify the file change time zone.

# Vi/etc/sysconfig/clock Zone=asia/shanghai (check/usr/share/zoneinfo file below) Utc=false Arc=false

# Rm/etc/localtime

# Ln-sf/usr/share/zoneinfo/asia/shanghai/etc/localtime

# Cat/etc/sysconfig/clock


The following is the system time definition function:

Change_time () {
/bin/rm-f/etc/localtime
Cp/usr/share/zoneinfo/asia/shanghai/etc/localtime

Cat >/etc/sysconfig/clock <<eof
Zone= "Asia/shanghai"
Utc=false
Arc=false
Eof

Cat >/etc/ntp.conf << EOF
Server cn.pool.ntp.org prefer
Server 210.72.145.44
Server Ntp1.cs.mu.OZ.AU
Server Ntp0.cs.mu.OZ.AU
Server ntp.alaska.edu
Driftfile/var/lib/ntp/ntp.drift
Eof

Pkill ntpd
Ntpdate cn.pool.ntp.org
/sbin/hwclock--SYSTOHC
}



System time under Linux

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.