在 linux 中递归地查找和替换文件中的文本

find and replace text in file recursively in linux

我需要在我的 Web 服务器上的所有文件中查找并替换部分文本。我知道这个命令(通过 Google'ing 它)作为

find . -type f -exec sed -i 's/foo/bar/g' {} +

但问题是我需要替换的文本中包含 /。例如我需要...

查找

/home/this/root/

/home/that/root/

由于上面的命令使用 / 作为分隔符来确定 find/replace 我如何在搜索中包含 / 以免命令混淆?

使用不同的 sed 定界符。

find . -type f -exec sed -i 's~foo~bar~g' {} +