Friday, January 5, 2018

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


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.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...