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

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


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/’


-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