Find and Replace Text in Multiple Files – Linux Command Line HOWTO

Tonight we were switching a clients WordPress site to a new domain name and in the process found some of the old domain was hard coded into PHP files.  There were too many to try and sort through them, plus I was likely to miss something.  I knew a script was needed.  My Google-fu was weak, I tried some posted tips on how to do this using perl and php commands but found they didn’t work in our environment.  Finally I remembered a tool we used to search and insert scripts in the hosted PBX environment I used to maintain.  sed.  I found good old sed worked best for this:


Try it out for yourself, and of course an obligatory shout out to my cousin Gabe Anderson for posting a perl script that worked for him 4 years ago.

One thought on “Find and Replace Text in Multiple Files – Linux Command Line HOWTO”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>