[英]Need to delete first N lines of grep result files
I'm trying to get rid of a hacker issue on some of my wordpress installs. 我正在尝试摆脱某些Wordpress安装中的黑客问题。
This guy puts 9 lines of code in the head of multiple files on my server... I'm trying to use grep and sed to solve this. 这个家伙在我的服务器上的多个文件的开头放了9行代码。。。我正在尝试使用grep和sed解决此问题。
Im trying: 我尝试着:
grep -r -l "//360cdn.win/c.css" | xargs -0 sed -e '1,9d' < {}
But nothing is happening, if I remove -0 from
xargs , the result of the files found are clean, but they are not overwriting the origin file with the
sed` result, can anyone help me with that? 但是什么也没发生,如果我
-0 from
xargs中删除-0 from
, the result of the files found are clean, but they are not overwriting the origin file with the
sed`结果, the result of the files found are clean, but they are not overwriting the origin file with the
,有人可以帮助我吗?
Many thanks! 非常感谢!
You should use --null
option in grep
command to output a NUL byte or \\0
after each filename in the grep
output. 您应该使用
--null
在选项grep
命令输出NUL字节或\\0
在每个文件名后grep
输出。 Also use -i.bak
in sed
for inline editing of each file: -i.bak
sed
-i.bak
用于每个文件的内联编辑:
grep -lR --null '//360cdn.win/c\.css' . | xargs -0 sed -i.bak '1,9d'
What's wrong with iterating over the files directly¹? 直接遍历文件有什么问题¹?
And you might want to add the -i
flat to sed so that files are edited i n-place 你可能要添加
-i
平的sed,使文件进行编辑我正地方
grep -r -l "//360cdn.win/c.css" | while read f
do
sed -e '1,9d' -i "${f}"
done
¹ well, you might get problems if your files contain newlines and the like. ¹很好,如果文件中包含换行符之类的内容,则可能会遇到问题。 but then...if your website contains files with newlines, you probably have other problems anyhow...
但是然后...如果您的网站包含带有换行符的文件,则可能仍然存在其他问题...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.