Linux search and replace

Search and Replace

If you want to search and replace text on a linux box you can use the tools grep and sed for revursive search and replace over a whole directory structure ...

The following command replaces all "searchstr" with "replacestr" in all subfolders. To limit this to a file filter you can replace "*" with something like "*.html" ... be careful with this command, because it changes all files directly without any further questions ...

grep -rl "searchstr" * | xargs sed -i -e 's/searchstr/replacestr/g'

Explanation on this command: