How to do a recursive find/replace of a string with awk or sed?

后端 未结 30 2114
盖世英雄少女心
盖世英雄少女心 2020-11-22 06:39

How do I find and replace every occurrence of:

subdomainA.example.com

with

subdomainB.example.com

in eve

30条回答
  •  没有蜡笔的小新
    2020-11-22 07:29

    find /home/www/ -type f -exec perl -i.bak -pe 's/subdomainA\.example\.com/subdomainB.example.com/g' {} +
    

    find /home/www/ -type f will list all files in /home/www/ (and its subdirectories). The "-exec" flag tells find to run the following command on each file found.

    perl -i.bak -pe 's/subdomainA\.example\.com/subdomainB.example.com/g' {} +
    

    is the command run on the files (many at a time). The {} gets replaced by file names. The + at the end of the command tells find to build one command for many filenames.

    Per the find man page: "The command line is built in much the same way that xargs builds its command lines."

    Thus it's possible to achieve your goal (and handle filenames containing spaces) without using xargs -0, or -print0.

提交回复
热议问题