Remove files, which provided by pipe

14,724

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:
14,724

Related videos on Youtube

Roland Soós
Author by

Roland Soós

Updated on September 17, 2022

Comments

  • Roland Soós
    Roland Soós over 1 year

    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?

  • Roland Soós
    Roland Soós over 13 years
    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?
  • Shawn J. Goff
    Shawn J. Goff over 13 years
    @Roland add cut -f2 -d' ' to the pipeline right before the suggested xargs
  • Luis
    Luis over 13 years
    try xargs -n1 rm -f
  • Roland Soós
    Roland Soós over 13 years
    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'