Here is a command line method to replace a string in multiple files in the current and sub directories.
grep -rli 'old string' --include=*.php | xargs -i@ sed -i 's/old string/new string/g' @
This basically asks grep to do a recursive search and list all the php files in the current directory and all sub-directories with the string – ‘old string‘
Then on each file in the list, you are using sed to replace the string ‘old string‘ with ‘new string‘
You can include more file types in the grep search by changing the include flag to something like
One thought on “String replace in multiple files using a recursive file search”
There is also the Perl pie method.