If I go into /etc/apache2/
and type grep -rl 'LoadModule php' ./*
then I'll only see ./mods-available/php7.0.load
. If I change r
to R
then I'll see
./mods-available/php7.0.load
./mods-enabled/php7.0.load
Both of these are plain directories. I'd expect -r
to cause grep to recurse all files/dirs in the PWD. What's going on with -r
? I'm minded to just always use -R
at this point.
According to manpage of grep:
Example:
I have a folder test in which there is a file 1.txt. 2.txt is a symbolic link to 1.txt such that output of
ls -l test
looks like:The content of 1.txt is:
If I want to search for "file" string in files inside test folder and I run:
I'll encounter an error:
But if I do:
I get an output:
On the other hand if I run:
I get output:
Here, I haven't explicitly mentioned to scan all the files. So, when I used
R
flag, symbolic link (here 2.txt) was respected and output was generated. But when I usedr
flag, symbolic link was ignored simply because I didn't mention to scan 2.txt also.From GNU grep v2.11-8 and above, if invoked with
-r
excludes symlinks not specified on the command line and includes them when invoked with-R
(source).From manual page (
man grep
):