How to find and replace every occurrence of String (From example1.com to example2.com) in all files in sub-folders recursively.

FIND and REPLACE every occurrence of a STRING in all files ::

From
example1.com
With
example2.com

in every text file under the /var/www/html/ directory tree (recursive find/replace).

~# cd /var/www/html/
~# find . -type f -print0 | xargs -0 sed -i ‘s/example1.com/example2.com/g’

Done!

Note:-
-print0 (GNU find only) tells find to use the null character (\0) instead of whitespace as the output delimiter between pathnames found. This is a safer option if you files can contain blanks or other special character. It is recommended to use the –print0 argument to find if you use -exec command or xargs (the -0 argument is needed in xargs.).

Content credit: djmaza