返回列表 发帖

[问题求助] sed如何替换指定文本中的特定字符串

想要批量修改Linux 的一些配置文件
对sed不是太熟悉,找到了这个比较笨的方法,修改HOSTNAME成功了
可是修改SELINUX的配置文件确出了问题
#sed -i '/HOSTNAME/d' /etc/sysconfig/network
#echo  'HOSTNAME=testname' >> /etc/sysconfig/network
#sed -i '/SELINUX/d' "/etc/selinux/config"
#echo  'SELINUX=disablexxx' >> "/etc/selinux/config"COPY
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted COPY
# This file controls the state of SELinux on the system.
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUX=disablexxxCOPY
修改完了,成了这样,后面的内容都被删除了。
正确的使用sed修改某个参数的方法是什么?

回复 3# DiamondbacK

好用多谢,试着理解理解我

TOP

返回列表