涉及知识点:shell基本操作,如if,中括号,取反符号,binary to text,软链接以及时区的基本知识。

if [[ ! `grep -a CST-8 /etc/localtime` ]]; then  
    rm -rf /etc/localtime   
    ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime   
fi

其中grep的-a选项可以读入一个二进制文件,即binary to text,否则可能会遇到如下报错:“Binary file (standard input) matches”。