linux设置系统时区,tzselect命令可以设置系统时区,但是是临时生效的方式,当系统重启或重新登录后有会恢复到原来默认时区。
一、tzselect命令设置时区
date -R #查看当期时区 tzselect #设置时区
设置后会提示永久生效的提示,提示信息如下:
You can make this change permanent for yourself by appending the line TZ='Asia/Shanghai'; export TZ to the file '.profile' in your home directory; then log out and log in again. Here is that TZ value again, this time on standard output so that you can use the /usr/bin/tzselect command in shell scripts: Asia/Shanghai
按提示执行命令:
TZ='Asia/Shanghai'; export TZ #配置用户目录下文件,追加内容TZ='Asia/Shanghai'; export TZ vim /root/.bash_profile >> TZ='Asia/Shanghai'; export TZ
二、另设置时区永久生效方式
ll /etc/ |grep localtime #查看当前localtime被软连接地址 ll /usr/share/zoneinfo #查看目录种的时区
配置:
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime