1、指定目录 terry 下的所有文件内容中,把 terry 替换为 breakeast ,此处为 正则替换,需要进行转义处理
find ./terry -type f | xargs perl -i -pe s%terry%breakeast%g
2、指定替换文件类型
find ./terry "*.html" -type f | xargs perl -i -pe s%terry%breakeast%g
3、若要替换时,同时生成备份,则需要写shell脚本实现:
#!/bin/bash
str="www.breakeast.com"newstr="blog.breakeast.com"for i in `find ./terry/`dogrep "$str" $iif [ $? == 0 ]thenecho $icp $i $i.newfile
sed "s/$str/$newstr/g" $i fidone源于博客http://www.qing.es