已知linux系统大多通过例如:
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
或
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
来设定当前时区。
那么如何通过这个localtime文件逆向查找到本系统设置的城市信息呢?
ringa_lee
Regarding your question, if it is a soft link file, you can obtain the source file address through the readlink command:
# readlink /etc/localtime /usr/share/zoneinfo/Asia/Shanghai
If it is not a link file, it can be identified by comparing md5, because in most environments it should exist in the form of a soft link, so I actually copied the file here to test:
# cp /usr/share/zoneinfo/Asia/Shanghai abc # m=`md5sum abc | awk '{print }'` # find /usr/share/zoneinfo -type f | xargs md5sum | grep "$m" c103f379c73f61b9eaf39a9a8e0c2cb1 /usr/share/zoneinfo/Asia/Shanghai c103f379c73f61b9eaf39a9a8e0c2cb1 /usr/share/zoneinfo/PRC
If there is further need, for example, use a script to implement:
if [ -L “/etc/localtime” ]; then # is symbolic link ... else # normal file ... fi
Regarding your question, if it is a soft link file, you can obtain the source file address through the readlink command:
If it is not a link file, it can be identified by comparing md5, because in most environments it should exist in the form of a soft link, so I actually copied the file here to test:
If there is further need, for example, use a script to implement: