All my index.php were injected with
<script type='text/javascript' src=’https://www.example.com/home?v=2.2.0′></script>
at the 1st line of it.
So I want to just remove that particular line "<script type=’text/javascript’ src=’https://www.example.com/home/public′></script>"
via Terminal in Cpanel running CentOS
I do some research and I have came up with this :
find . -name “index.php” -exec sed -i “s#<script type=’text/javascript’ src=’https://www.example.com/home?v=2.2.0′></script>##g"; {} +
The terminal shows an error :
find: missing argument to `-exec’
bash: {}+: command not found
2
Answers
You’ve just ended your line too fast! The
;
should be at the end of the line.(be careful, there some quotes/anti quotes or typographic quotes in your example… it could be confusing)
But I see 2 informations in your question (first line + a pattern).
The easiest way (not the only one), wouldn’t be to delete the first line of all the index.php files?
If so, just use:
You also can use
for
instead ofexec
:On macOS/freeBSD style, just add
''
insed
:If you are looking to delete an entire pattern, you will need to protect special chars and so on, and you will need to be careful not to delete, for example, the same but useful pattern at any other place in your files. So be careful.
I assume that’s because you are using hash character
#
as regex delimiter.My personal favorite there is using at sign
@
for the same, thus: