How do I find and replace every occurrence of:
subdomainA.example.com
with
subdomainB.example.com
in every text file under the /home/www/
directory tree recursively?
find /home/www \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i 's/subdomainA\.example\.com/subdomainB.example.com/g'
From man find
:
-print0 (GNU
find
only) tellsfind
to use the null character (\0
) instead of whitespace as the output delimiter between pathnames found. This is a safer option if your files can contain blanks or other special characters. It is recommended to use the-print0
argument tofind
if you use-exec <command>
orxargs
(the-0
argument is needed inxargs
.)