i have many php files maybe over Three million..
how can i use grep with xargs and find with mv to find contain the string in files and move them to directory if they match.

I try like that

find . -iname \*.php\* | xargs -n64 grep -hEl 'to times' | xargs -0 -I {} mv {} old/

that doesn't do anything.

but if i run without the second xargs i got result like this...right files


1 Answer 1


Find files that matches '*.php*

find . -type f -name '*.php*' |

then pass each file name to grep which will output only file names if 'to times' string wil be found

xargs -I {} grep -l 'to times' '{}' |

then pass each file name to mv

xargs -I {} mv '{}' old/
  • ... this work with me . thanks for your help & for the simplified explanation. Oct 31, 2015 at 11:20

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.