CentOS language, time zone, and time modification

Source: Internet
Author: User
Tags time zones

CentOS language, time zone, and time modification

Modify language:

# Vi/etc/sysconfig/i18n
LANG = "en_US.UTF-8"
SYSFONT = "latarcyrheb-sun16"

Modify the/etc/sysconfig/clock file:

ZONE = "Asia/Shanghai"

UTC = true

ARC = false

Add the/etc/profile file

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
source /etc/profile

Modify the time zone:

The newly installed server may be set incorrectly. You need to adjust the time zone and adjust the time as follows: Use NTP to synchronize data from a time server.

Cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime

Ntpdate us.pool.ntp.org

The first sentence is to change the current time zone to Shanghai, which is + 8. If you want to change the other time zones, you can check the/usr/share/zoneinfo directory;

The second sentence is to use ntpdate to synchronize the standard time.

If ntpdate is not installed, you can run yum:

Yum install ntp

Add scheduled tasks and synchronize the clock every 10 minutes

Crontab-e

*/10 * root/usr/sbin/ntpdate us.pool.ntp.org | logger-t NTP

China National Time Service Center:
Http://www.time.ac.cn/stime.asp

Other network time server addresses are as follows: (You can also search for them by yourself)

Time.nist.gov (USA)
Ntp.fudan.edu.cn (Fudan ))(This server is recommended for domestic users)
Timekeeper.isi.edu
Subitaneous. cpsc. ucalgary. ca
Usno.pa-x.dec.com
Time.twc.weather.com
Swisstime. ethz. ch
Ntw.fau.de
Ntp3.fau.de
Time-a.nist.gov
Time-b.nist.gov
Time-nw.nist.gov
Nist1-sj.glassey.com

210.72.145.44 is also a good address, which is fast!

PS: if you do not have the permission, add

-A output-p udp -- dport 123-j ACCEPT

1>
Find the corresponding time zone file/usr/share/zoneinfo/Asia/Shanghai
Replace the current/etc/localtime file with this file.

Cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime
Or find the server that you think is the standard time, and then
# Scproot@xxx.xxx.xxx.xxx:/etc/localtime
2>
Modify the/etc/sysconfig/clock file:
ZONE = "Asia/Shanghai"
UTC = false
ARC = false

Modify Date and Time
1>
Use date to modify the date and time
# Date-s 08/24/2006
# Date-s 13:02:00
2>
Synchronizes the BIOS clock and forces the system time to be written to CMOS.
# Clock-w

In addition, use # hwclock-r to view Bois time
# Tzselect can be used to interactively modify the time zone


Linux System Time Zone Modification
1. view the current time zone

# Vi/etc/sysconfig/clock
2. Modify the time zone

Method (1) # tzselect method (2 Limited to RedHat Linux and CentOS) # timeconfig
3. Copy the corresponding time zone file to replace the default time zone of the system.

# Cp/usr/share/zoneinfo/$ main Time Zone/$ Time Zone/etc/localtime: # cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime
4. Write the current time into the BIOS for permanent effect (to prevent failure after restart)

# Hwclock

Generally, two methods are used to obtain the timestamp in the inux shell. One is to directly call the system variable; the other is to obtain the timestamp using a pure shell script. The example is as follows:

1. directly call System Variables

Obtain the current period: date + % Y % m % d' or date + % F

Get the period of yesterday: 'date-d yesterday + % Y % m % d'

Get date of the day before yesterday: 'date-d-2day + % Y % m % d'

And so on, for example, get the date 10 days ago: 'date-d-10day + % Y % m % d'

Note that there are spaces in the middle.

2. implement it by using shell. The following example shows the shell that calculates the date of yesterday when the current day is known.

Startdate = 'date'
D1 = 'date' + % Y % m % d''
If test! "$1" = ""
Then
D1 = $1
Fi
Echo "today is ${d1 }"
Yesterday ()
{
YEAR = 'expr substr "$ {d1}" 1 4'
MONTH = 'expr substr "$ {d1}" 5 2'
DAY = 'expr substr "$ {d1}" 7 2'
If [$ DAY-eq 1]
Then
If [$ MONTH-eq 1]
Then
YEAR = 'expr $ YEAR-1'
MONTH = 12
Else
MONTH = 'expr $ MONTH-1'
Fi
DAY = 'echo \ 'cal $ MONTH $ YEAR \ '| tail-n1 | awk' {print $ NF }''
Else
DAY = 'expr $ DAY-1'
Fi
D2 = 'echo "$ YEAR $ MONTH $ DAY" | awk '{if (length ($2) = 1) $2 = 0 $2; if (length ($3) = 1) $3 = 0 $3; printf "% s", $1, $2, $3 }''
}
Yesterday
Echo "yesterday IS ${d2 }"

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.