用于编辑 MongoDB 配置文件的 Bash 脚本



我想在安装时使用bash脚本将bindIp : 127.0.0.0替换为bindIP: 0.0.0.0。 有人可以告诉我如何通过 bash 做到这一点吗?

要编辑的部分:

# network interfaces
net:
port: 27017
bindIp: 127.0.0.0

将 127.0.0.0替换为 0.0.0.0

我正在使用的命令:

sed '0,/bindIp:*;/s//bindIp: 0.0.0.0;/' /etc/mongod.conf
sed "s,\(^[[:blank:]]*bindIp:\) .*,\1 0.0.0.0," /etc/mongod.conf

如果要即时编辑文件,请使用选项-i

sed -i "s,\(^[[:blank:]]*bindIp:\) .*,\1 0.0.0.0," /etc/mongod.conf

最新更新