find -exec grep 'string' result different from grep -r command's result

Why does this command

find /etc -exec grep student {} \; 2>/dev/null

show me more results than this command

grep -r student /etc 2>/dev/null

terminal window

2

1 Answer

Probably there are some symbolic links under your /etc. It looks like your grep -r doesn't follow them but find does.

Try grep -R.

Note: neither -r nor -R is required by POSIX. Some implementations of grep may not support them; some may support one of them, not necessarily following (or not) symbolic links like in this example; some may treat -R and -r alike. Refer to man 1 grep in your OS to be sure.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like