公司搬家了,几台server的ip也都变了,所以得把server里OTA应用相关的很多文件的ip替换成现在的ip,这时候就可以用sed命令了。在一个目录里批量查找替换的命令如下:
sed -i "s/
OldString/
NewString/g" `grep OldString -rl
Dir`
例如,把/product目录里所有的ip地址10.168.195.52替换成172.27.77.72,可以这样:
sed -i "s/10.168.195.52/172.27.77.72/g" `grep 10.168.195.52 -rl /product`
例如
[root@localhost local]# pwd
/usr/local
[root@localhost local]# ll
total 68
drwxr-xr-x. 2 root root 4096 Mar 16 18:04 bin
drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin
drwxr-xr-x. 8 root root 4096 Feb 1 20:16 service
[root@localhost local]# sed -i "s/222.223.205.189/192.168.100.11/g" `grep 222.223.205.189 -rl service`
/usr/local
[root@localhost local]# ll
total 68
drwxr-xr-x. 2 root root 4096 Mar 16 18:04 bin
drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin
drwxr-xr-x. 8 root root 4096 Feb 1 20:16 service
[root@localhost local]# sed -i "s/222.223.205.189/192.168.100.11/g" `grep 222.223.205.189 -rl service`