Linux: Find and Replace in Files

Thanks to Jon H., I can now do find and replace in files on Linux machines from the command line. Its pretty simple, but I had never bothered to figure it out.

Here are two examples. The first is for just one file, the meat and potatoes are in the second example, which does a find and replace in all PHP files.

1
2
sed -i -e "s/TOREPLACE/REPLACEMENT/g" temp.txt;
sed -i -e "s/TOREPLACE/REPLACEMENT/g" `find -name '*.php'`;

Super helpful.

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

One Comment to “Linux: Find and Replace in Files”

  1. Hi,
    Good post,
    very simple and easy to use.

    keep it up !
    :)

Leave a Reply