#sed 注释行的 4 种方法
sed -i 's/server 0.centos.pool.ntp.org/#&/' /etc/ntp.conf
sed -i '/server 1.centos.pool.ntp.org/s/^/#/' /etc/ntp.conf
sed -i 's/server 2.centos.pool.ntp.org iburst/#server 2.centos.pool.ntp.org iburst/' /etc/ntp.conf
sed -i 's/^server 3.centos.pool.ntp.org iburst/#&/' /etc/ntp.conf #替换以server 3.centos.pool.ntp.org iburst开头的;&的意思是匹配任意字符(就是说未知数,啥都行)
sed -i '25a\server 10.0.13.100' /etc/ntp.conf #配置上游时间服务器为本地的ntpd Server服务器
sed -i '26a\restrict 10.0.13.100 nomodify notrap noquery' #配置允许上游时间服务器主动修改本机的时间
#sed取消注释行
sed -i 's/^#\(server 0.centos.pool.ntp.org iburst\)/\1/' /etc/ntp.conf
sed -i 's/^#\(server 1.centos.pool.ntp.org iburst\)/\1/' /etc/ntp.conf ##\1的意思 就类似于 前面的 (bbb\) \1就是复制这个位置的内容 如果有 第二个 那么久\2就是复制第二个位置的内容
sed -i 's/^#server 2.centos.pool.ntp.org iburst/server 2.centos.pool.ntp.org/' /etc/ntp.conf
sed -i 's/^#\(server 3.centos.pool.ntp.org iburst\)/\1/' /etc/ntp.conf