搜索并替换linux目录的所有文件中的文本

时间:2022-03-30 16:51:27

I have a website directory where I need to change all hardcoded links from one domain to another. Looking for a single (grep? sed?) bash command that will allow me to change all occurrences of text in all files in the directory?

我有一个网站目录,我需要将所有硬编码链接从一个域更改为另一个域。寻找单个(grep?sed?)bash命令,它允许我更改目录中所有文件中出现的所有文本?

2 个解决方案

#1


47  

The following will do it:

以下将做到:

sed -i 's/old_link/new_link/g' file...

Don't forget to escape any slashes, dots, and any other regex special chars in the link addresses with a backslash.

不要忘记使用反斜杠转义链接地址中的任何斜杠,点和任何其他正则表达式特殊字符。

#2


2  

Also, try:

另外,尝试:

perl -p -i -e <regex> <folder>

#1


47  

The following will do it:

以下将做到:

sed -i 's/old_link/new_link/g' file...

Don't forget to escape any slashes, dots, and any other regex special chars in the link addresses with a backslash.

不要忘记使用反斜杠转义链接地址中的任何斜杠,点和任何其他正则表达式特殊字符。

#2


2  

Also, try:

另外,尝试:

perl -p -i -e <regex> <folder>