Skip to content

Linux – Recursively find and replace content in all files

We recently changed our server architecture, requiring that all the websites hosted on our server have localhost changed to an IP Address.

Instead of manually editing this content, I decided to find a simple command line way to accomplish my task. Below you will find the result.

find ./ -type f -exec sed -i 's/findString/replaceString/' {} \;

The preceeding will loop through whichever directory it is run from and locate “findString” and replace it with “replaceString”.

Posted in Linux.

One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Steven D. Morrey said

    find ./ -type f -exec sed -i ‘s/findString/replaceString/g’ {} \;

    Is more correct since /g means globally, the other only grabs the first instance.

Some HTML is OK


(required, but never shared)

or, reply to this post via trackback.