GNU bug report logs - #47649
grep bug report - improper handling of file symlinks with -r option

Previous Next

Package: grep;

Reported by: Chris Drake <cryptophoto <at> gmail.com>

Date: Thu, 8 Apr 2021 02:11:01 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 47649 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Chris Drake <cryptophoto <at> gmail.com>
Cc: 47649 <at> debbugs.gnu.org
Subject: Re: bug#47649: grep bug report - improper handling of file symlinks
 with -r option
Date: Fri, 6 Aug 2021 22:10:22 -0700
tags 47649 notabug
close 47649
done

On Wed, Apr 7, 2021 at 7:21 PM Chris Drake <cryptophoto <at> gmail.com> wrote:
> *This is the original working grep behaviour - it found text inside files
> that were symlinks:-*
> (Note the output: "*./folder/testfile1:this is my test file*")
>
> [root <at> ir2 ~]# grep --version
> grep (GNU grep) 2.5.1
>
> Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
> [root <at> ir2 ~]# mkdir bugdemo
> [root <at> ir2 ~]# cd bugdemo
> [root <at> ir2 bugdemo]# echo "this is my test file" > testfile1
> [root <at> ir2 bugdemo]# echo "this is my test file" > testfile2
> [root <at> ir2 bugdemo]# mkdir folder
> [root <at> ir2 bugdemo]# cd folder
> [root <at> ir2 folder]# echo "this is my test file" > testfile3
> [root <at> ir2 folder]# ln -s ../testfile1
> [root <at> ir2 folder]# cd ..
> [root <at> ir2 bugdemo]# unalias grep
> [root <at> ir2 bugdemo]# grep -r test .
> ./testfile2:this is my test file
> ./folder/testfile1:this is my test file
> ./folder/testfile3:this is my test file
> ./testfile1:this is my test file
> [root <at> ir2 bugdemo]#
...
> It looks like processing exists to not recursively follow symlinks, and
> someone has messed with that which has caused files to no longer be
> searched by mistake.

Thanks for the report, but that is the documented behavior of -r.
You appear to prefer -R:

‘-r’
‘--recursive’
     For each directory operand, read and process all files in that
     directory, recursively.  Follow symbolic links on the command line,
     but skip symlinks that are encountered recursively.  Note that if
     no file operand is given, grep searches the working directory.
     This is the same as the ‘--directories=recurse’ option.

‘-R’
‘--dereference-recursive’
     For each directory operand, read and process all files in that
     directory, recursively, following all symbolic links.




This bug report was last modified 3 years and 283 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.