0

I've got a large problem. I'm trying to remove malware code from first lines of php files in my project but all the time console returns:

sed: 1: "./{PATH_TO_FILE}": invalid command code .

My request:

find . -name "*.php" -type f -exec sed -n -i '1s/.*/<?php/' {} \;

Can anyone tell me what is wrong here? :)

Thanks a lot in advance!

Sean Bright
  • 118,630
  • 17
  • 138
  • 146

2 Answers2

2

First of all, you didn't put the wildcard in ".php". it should be "*.php".

find . -name "*.php"

Second, you forgot to add the place-holder for the file name in the exec clause and the end of the exec clause (a semi-colon):

Third, your sed expression is invalid. If what you want to achieve is to delete the first line then '1d' should make it:

-exec sed -n -i '1d' {} \;

Finally, -n seems to interfere with the -i, so just remove it.

Your full command should be:

find . -name "*.php" -type f -exec sed -i '1d' {} \;

  • Good points (combining `-n` with `-i` actually _truncates_ the input file, because `-n` suppresses all (implicit) output so that _nothing_ is written back to the input file). However, the intent was to _replace_ the 1st line with ` – mklement0 Oct 14 '15 at 14:45
1

Thanks a lot ! Finally i sloved problem using command

LC_ALL=C find . -name "*.php" -type f -exec sed -i '' -e "s/^<\?php.*\?>//" {} \;