[英]How can I find & replace text in HTML, htm, PHP and txt files on a Linux server?
I would like to know how to find and replace text in all HTML, htm, PHP and txt extension files on Linux server at hosting provider. 我想知道如何在托管服务提供商的Linux服务器上查找和替换所有HTML,htm,PHP和txt扩展文件中的文本。 I can do SSH.
我可以做SSH。
Text to be found : http://mydomain.example.com
可以找到的文字 :
http://mydomain.example.com
: http://mydomain.example.com
Text to be replaced with : http://otherdomain.example.com/MyDomain
文本替换为 :
http://otherdomain.example.com/MyDomain
: http://otherdomain.example.com/MyDomain
Please give me exact command and it would be much helpful if it can prompt for confirmation before replacement. 请给我确切的命令,如果它可以提示您在更换前进行确认,这将非常有帮助。
Here's one way using sed
and a for
loop. 这是使用
sed
和for
循环的一种方法。 Use the -i
flag with mv
to prompt before overwrite: 在覆盖前使用
-i
标志和mv
提示:
for i in *.html *.htm *.php *.txt; do sed 's%\(http://www\.\)\(MyDomain\)\(\.com\)%\1OtherDomain\3/\2%g' "$i" > tmp && mv -i tmp "$i"; done
sed -i 's/http:\/\/www.mydomain.com/http:\/\/www.otherdomain.com\/MyDomain/gi' *.txt *.html *.htm *.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.