We often need to replace a particular text with a new text in every file in a directory. An example would be changing a common URI everywhere in a website's source directory.
Replacing a pattern with text in all the files in a directory
How to do it...
We can use find to locate the files to have text modified. We can use sed to do the actual replacement.
To replace the Copyright text with the Copyleft word in all .cpp files, use the following command:
find . -name *.cpp -print0 | \ xargs -I{} -0 sed -i 's/Copyright/Copyleft/g' {}
How it works...
We use find on the current directory (.)...