Linux Find and Replace in All Files

Finding and replacing a single string of text in all the files in a single linux directory is easy. Linux has a magical 'sed' command which is very powerful.

To find and replace all instances of a string with another string in all files type use the sed command:

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

Typing the above in a linux command line will go through the current directory, and look through every file. It will replace the string 'foo' with the string 'bar' in all these files.

The * is what specifies which files to look through. If you onlly want to look through files ending in .txt, you would type:

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

Linux has some very powerful commands.