sh 轻松设置ubuntu系统日期/时间和时区

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 轻松设置ubuntu系统日期/时间和时区相关的知识,希望对你有一定的参考价值。

#!/bin/sh

# change this value to suit you, see below for further guidance
DESIRED_TIME_ZONE="US/Central"
# Note, if you were to get this value from an argument etc, keep
# in mind it would be vulnerable to command injection

# get timezone values from `ls /usr/share/zoneinfo` if you need them
# for example, you can see there's a /usr/share/zoneinfo/US/Central and
# /usr/share/zoneinfo/America/Chicago etc

# you shouldn't have to change anything below here

# actually set the timezone (overwrite the symbolic link)
echo "Setting timezone ($DESIRED_TIME_ZONE)"
sudo ln -sf /usr/share/zoneinfo/$DESIRED_TIME_ZONE /etc/localtime
sudo sh -c "echo $DESIRED_TIME_ZONE > /etc/timezone"

# get the current time from the Internet so we can automate this
# ignore "too far in the future" err if you get it
echo "Getting current time from timeapi.org" 1>&2
new_time=`wget -q -O - http://www.timeapi.org/utc/now.json | cut -d '"' -f 4`
echo "Got ($new_time)" 1>&2
echo "Setting date and time" 1>&2
sudo date -s "$new_time"

以上是关于sh 轻松设置ubuntu系统日期/时间和时区的主要内容,如果未能解决你的问题,请参考以下文章

linux实验二

CentOS/RHEL/Ubuntu更改系统时间OR时区

CentOS/RHEL/Ubuntu更改系统时间OR时区

Ubuntu怎么修改时区?

Ubuntu下设置系统时区

Ubuntu下设置系统时区