Bash – List all files containing a specific string

bash

I need to recursively look for all files containing a specific string so that I can copy a new file over the old one. E.g.:

If a file has the string "replace me":

  1. find the full path of the files:

    /dir/of/file/filename.php
    /dir/of/different/file/filename.php
    
  2. replace the file with my new filename.php file.

It sounds simple, but I have wasted several hours on it getting nowhere.

Best Answer

find some/dir \
    -exec grep -q "replace me" {} \; \
    -exec cp some/new/filename.php {} \;
Related Question