Find and Replace within Files

duanestubbs's picture
Find and Replace text in files from the command line
Search through all the files and sub-folders (remove R from -RIZ to just do current directory) and replace text within files.

grep -RlZ {search text in files} . \ | xargs -0 -l  sed -i -e 's/{find}/{replace}/'


If you need to replace the IP address with within php files (*.php), cd to the directory containing the files, then type:

grep -RlZ *.php \ | xargs -0 -l  sed -i -e 's/'  


Warning: the changes cannot be undone, unless your do another find and replace of course!