Ubuntu 16.04/18.04 LTS改变时区和语言

Ubuntu 16.04/18.04 LTS改变Timezone时区设定

原文 https://www.phpini.com/linux/ubuntu-16-04-change-timezone-setting
相关资料 http://manpages.ubuntu.com/manpages/trusty/man3/DateTime::TimeZone::Catalog.3pm.html

这里转发两种在终端设置时区的方法:

1.#dpkg-reconfigure tzdata
用root身份用dpkg-reconfigure 设定Ubuntu的Timezone,好处是有一个菜单可以选择地区,不用记着时区的字串。
出现“Configuringtzdata”后,先选择地区,亚洲地区选择“Asia”,然后再选择所在城市,按“OK”后便完成,同时系统会印出新的Timezone时区设定。

2.#timedatectl
另一个方法是用timedatectl,使用前先用以下指令取得Timezone列表:
#timedatectl list-timezones
但Timezone列表十分长,用grep过滤会较方便,以下只会印出亚洲区的时区:
#timedatectl list-timezones|grep Asia
找到要设定的时区后,便可以设定:
香港时区:#timedatectl set-timezone Asia/Hong_Kong
台北时区:#timedatectl set-timezone Asia/Taipei
设定好后,可以用timedatectl 指令检查时区是否设定正确:

#timedatectl

#!/usr/bin/env bash
# 设定系统时区为香港时区
read -p "Timezone (default: Asia/Hong_Kong): " TZONE
TZONE=${TZONE:-'Asia/Hong_Kong'}
timedatectl set-timezone $TZONE
# 设定系统语言为中文,编码格式为 UTF-8
# 查询系统已安装的语言       locale -a
# 查询到的系统语言不一定是统一的 zh_CN.UTF-8 也可能是 zh_CN.utf8 或者别的
apt install -y language-pack-zh-hans language-pack-zh-hant
/usr/sbin/update-locale LANG=zh_CN.UTF-8









猜你喜欢

转载自blog.csdn.net/tty521/article/details/80979558