How to find and replace all occurrences of a string recursively in a directory tree?

前端 未结 8 1592
野性不改
野性不改 2020-12-12 18:01

Using just grep and sed, how do I replace all occurrences of:

a.example.com

with

b.example.com

within a

8条回答
  •  鱼传尺愫
    2020-12-12 18:28

    it is much simpler than that.

    for i in `find *` ; do sed -i -- 's/search string/target string/g' $i; done
    

    find i => will iterate over all the files in the folder and in subfolders.

    sed -i => will replace in the files the relevant string if exists.

提交回复
热议问题