environment:
Centos7.7
Problem Description:
How does Centos7 use commands to directly change the contents of the configuration file
The DNS in the ifcfg-bond1 file wants to be replaced and changed to 114
solution:
1. Use the sed command
sed -i -e "s:匹配参数=.*:匹配参数=替换后的内容:g" 对应的文件路径
This case order
sed -i -e "s:DNS=.*:DNS=114.114.114.114:g" /etc/sysconfig/network-scripts/ifcfg-bond1
Original content
changed
2. Script
1.sh脚本
#!/bin/bash
TEST_CONF=/etc/sysconfig/network-scripts/ifcfg-bond1
sed -i -e "s:DNS=.*:DNS=114.114.114.114:g" ${TEST_CONF}
echo "ok success!"