替换文件中字符串的脚本
# 打开文件并读取内容
with open('/etc/network/interfaces.d/eth0', 'r') as file:
file_content = file.read()
# 将所有的字符串192.168.1.91替换为192.168.5.91
new_content = file_content.replace('192.168.1.91', '192.168.5.91')
# 写入替换后的内容回文件
with open('/etc/network/interfaces.d/eth0', 'w') as file:
file.write(new_content)
print("替换完成")
在armbian中测试成功
浙公网安备 33010602011771号