How to find and replace in specific file type everywhere in a directory

I want to find a keyword in only php files and replace the same with new keyword, How can I do it in linux?

Tagged:

Answers

  • You can use find command.


    -type f :look into files only

    -name '*.php' :for file extension php only

    -exec :executing grep

    find ./ -type f -name '*.php' -exec sed -i -e 's/OldKeyword/NewKeyword/g' {} \;
    


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!