1

The first line returns dozens of finds. The second line returns nothing.

sudo find /var/www/ . -type 'f' -name index.php | grep "php"           
sudo find /var/www/ . -type 'f' -name index.php | grep "require" 

There are files called index.php that contain both text strings. Why doesn't the second line seem to work?

1 Answer 1

1

You want to be calling xargs before piping to grep. What you have is grep searching the results of find, not the contents of the files that find has found.

sudo find /var/www/ . -type 'f' -name index.php | xargs grep "php"

If you do lots of searching like this, you may want to look at ack. For instance, to search all the PHP files in /var/www for "require", you would use:

ack --php require /var/www

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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