Find and replace string within files in an entire directory tree

This will allow you to change a string within all files in an entire directory structure. I had taken on a project from a client that had a static website and whomever had created it, using whatever system they decided on, used a really crappy file name structure. Since everything was flat-file, to change a files name and location required editing all other files and updating the menu link.

The following two commands do the same thing, one uses SED and the other PERL. It's your choice.


find ~/location/ -name "*.*"|xargs perl -w -i -p -e "s/What To Find/Replace With What/g"


find ~/location/ -type f -print0 | xargs -0 sed -e 's/my-silly-home-page-name\.html/index\.html/g' -i

The backslashes before the .html escape the period character as it typically is a special character in regular expressions.