批量关闭自启动服务 引用 \1: 为(.*)里内容crontab。 如果前面有两个(.*)则第二个括号用\2调

批量关闭自启动服务   引用 \1: 为(.*)里内容crontab。 如果前面有两个(.*)则第二个括号用\2调

http://www.90root.com/archives/862

 

[root@node1 ~]# runlevel                         #查看当前系统运行级别
[root@node1 ~]# chkconfig –list             #查看自启服务、级别
11
比如说当前级别只允许ssh、network、rsyslog、crond开机自启。
[root@node1 ~]# for name in chkconfig --list|awk '{print $1}' |grep -Ev 'ssh|network|rsyslog|crond';do chkconfig $name off;done
[root@node1 ~]# chkconfig –list|grep 3:on
图片
比如说当前级别只允许ssh、network、rsyslog开机自启。
[root@node1 ~]# chkconfig –list|grep 3:on |awk ‘{print $1}’ |grep -Ev ‘ssh|network|rsyslog’
crond
[root@node1 ~]# chkconfig –list|grep 3:on |awk ‘{print $1}’ |grep -Ev ‘ssh|network|rsyslog’|sed -r ‘s#(.*)#chkconfig \1 off#g’|sh
[root@node1 ~]# chkconfig –list|grep 3:on |awk ‘{print $1}’ |grep -Ev ‘ssh|network|rsyslog’
图片
哈哈, 截图有点乱,仔细看
解释: 
          grep -E等于egrep    匹配多个关键字
          sed -r: -r 无须转意
          (.*):  .表示任意一个字符, *表示0个或多个前面字符,(.*)整体表示crond简称后向引用.凡是用(.*)后面都可以通过\1调用
          \1: 为(.*)里内容crontab。 如果前面有两个(.*)则第二个括号用\2调
 
sed转意演示
[root@node1 ~]# echo 90root > test.txt
[root@node1 ~]# sed -r ‘s#(.*)#This is \1#g’ test.txt
This is 90root
[root@node1 ~]#
This is 90root
图片

 

linux基础

有 2 条《批量关闭自启动服务》的回复

    1. sed -r: -r 无须转意
      (.*): .表示任意一个字符, *表示0个或多个前面字符,(.*)整体表示crond简称后向引用.凡是用(.*)后面都可以通过\1调用
      受教了

posted @ 2015-11-29 17:51  huangchaolilli  阅读(390)  评论(0)    收藏  举报