sed 注释行的 方法

#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
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值