Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 4 down vote accepted

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).

share|improve this answer
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
@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 posting your answer, you agree to the privacy policy and terms of service.

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