Easiest way to recursively find and replace?

GNU find

find /path -type f -iname "*.txt" -exec sed -i.bak 's/foo/bar/g' "{}" +;

grep is only used to find things, not to modify them.

For modifications with a grep-like interface, you'd typically use sed. By itself, sed doesn't support any kind of recursion though -- it only operates on one file at a time. To add that, you normally use find to find the files to contain the desired pattern, then have it invoke sed to modify the file.


zsh

sed -i 's/foo/bar/g' **/*.txt

Tags:

Grep

Replace