Page 1 of 1

command to find and replace a word in files directory wide

Posted: 2006/02/09 06:57:42
by dwhs
I need to replace word everywhere in the files in the home directory.

For example the word flippy needs to be flipper for every file.

Anyone know the command for find and replace words in all files directory wide?

Thanks, Steve :-)

Re: command to find and replace a word in files directory wide

Posted: 2006/02/26 05:17:10
by OraISV
This perl command will do it:

perl -pi -e 's?old_string?new_string?g' `grep -lr old_string . `

Be sure to test first in a harmless directory .. It will find every instance and modify it
and it won't ask you if you really mean it.

This: 's?old_string?new_string?g' means substitute old string with new string everywhere.


You can see which files it will do by just using the last part of the command:
grep -lr old_string .

Now you can really be dangerous .....