How do I replace every occurrence of a string with another string below my current directory?
Example: I want to replace every occurrence of www.fubar.com with www.fubar.ftw.com in every file under my current directory.
From research so far I have come up with
sed -i 's/www.fubar.com/www.fubar.ftw.com/g' *.php
You’re on the right track, use
findto locate the files, thensedto edit them, for example:Notes
.means current directory – i.e. in this case, search in and below the current directory.sedyou need to specify an extension for the-ioption, which is used for backup files.-execoption is followed by the command to be applied to the files found, and is terminated by a semicolon, which must be escaped, otherwise the shell consumes it before it is passed to find.