I have this command chain:

find . -print | grep php | xargs grep 'eval' -sl | xargs wc -l | grep ' [1-2][0-9] '

This provide me this output:

 14 ./includes/js/calendar/lang/vgju.php
 18 ./includes/phpInputFilter/default.php
 14 ./includes/Archive/eula.php
 18 ./media/system/js/json.php

This files are infected php files and I would like to remove it with my chain. How can I do it?


Although you can probably do this whole thing with find command only you can try appending |xargs rm -f to that command.

Here's what it would look like

find . -print | grep php | xargs grep 'eval' -sl | \
    xargs wc -l | grep ' [1-2][0-9] ' | \
    cut -f 2 -d ' ' | xargs rm -f

Note that the xargs rm command works here because you know there aren't any special characters in the file names. If there might be spaces in the file names, you can use xargs -d '\n' rm -f (Linux only).

  • This wont work, because there is the line numbers in the output of my command. Is there some substring command wherewith I could split the lines after the line number? – Roland Soós Jan 14 '11 at 18:56
  • 1
    @Roland add cut -f2 -d' ' to the pipeline right before the suggested xargs – Shawn J. Goff Jan 14 '11 at 18:59
  • try xargs -n1 rm -f – Luis Jan 14 '11 at 19:00
  • Thanks for both of your. Luis solution worked. Now I get the full list with this funny command: find . -print | grep php | xargs grep 'eval' -sl | xargs wc -l | grep ' [1-2][0-9] ' | xargs -n1 | grep 'php' – Roland Soós Jan 14 '11 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.