Linux sed combined with find command

Using sed with the find command

Purpose: Replace all files ending with *.sh in the /root/kang directory and the string of oldboy in the content with kang

[root@localhost kang]# find /root/kang/ -type f -name "*.sh"|xargs 
/root/kang/nginx/abc.sh /root/kang/test.sh     #查出总共有两个文件
[root@localhost kang]# find /root/kang/ -type f -name "*.sh"|xargs cat    #查看文件内容
oldboy
oldboy
[root@localhost kang]# find /root/kang/ -type f -name "*.sh"|xargs sed   's#oldboy#kang#g'       #查找替换,并打印出来(原文件并没有更改)
kang
kang
[root@localhost kang]# find /root/kang/ -type f -name "*.sh"|xargs sed -i 's#oldboy#kang#g'       #查找并替换原文件内容
[root@localhost kang]# find /root/kang/ -type f -name "*.sh"|xargs cat
kang
kang
[root@localhost kang]# 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325333202&siteId=291194637