# 打开文件并读取内容 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中测试成功
标签:脚本,文件,192.168,content,file,字符串,替换 From: https://www.cnblogs.com/sdwg518/p/17832134.html