use*_*277 4 sed centos timezone
在以前版本的 CentOS 上,我使用以下命令在我的 bash 脚本中获取当前时区:
timezone=$(sed 's/ZONE=//g' /etc/sysconfig/clock)
Run Code Online (Sandbox Code Playgroud)
输出是
"America/New_York"
如何在 CentOS 7 上获得准确的输出?
CentOS 7 具体:
timedatectl | gawk -F': ' ' $1 ~ /Timezone/ {print $2}'
Run Code Online (Sandbox Code Playgroud)
并只显示时区:
timedatectl | gawk -F'[: ]+' ' $2 ~ /Timezone/ {print $3}'
更通用:
date +%Z
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8039 次 |
| 最近记录: |