Ubuntu – Find and replace text within multiple files

text-editor

I want to know how I can find and replace a specific text in multiple files like in Notepad++ in the linked tutorial.

e.g.: http://cybernetnews.com/find-replace-multiple-files/

Best Answer

Here I use sed to replace every occurrence of the word "cybernetnews" with "cybernet" in every file with the extension, c, in the directory, /home/user/directory/.

find /home/user/directory -name \*.c -exec sed -i "s/cybernetnews/cybernet/g" {} \;

A more generic variation where you search recursively from the directory of execution and operate on only regular, readable, writeable files:

find ./ -type f -readable -writable -exec sed -i "s/cybernetnews/cybernet/g" {} \;