[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep bug

From: Bob Proulx
Subject: Re: grep bug
Date: Fri, 1 Apr 2005 10:48:49 -0700
User-agent: Mutt/1.5.8i

Curt Lewis wrote:
> If there is no file matching the filename pattern string in the current 
> directory in a recursive grep, it errors...
> example:
> fgrep -ri "cn: " *.ldif
> fgrep: *.ldif No such file or directory

Thank you for your report.  But this is not a bug in grep.  You are
misunderstanding how the -r option to grep works.

It works by traversing down the hiearchy of any command line argument
which happens to be a directory.  Since your pattern *.ldif did not
match any directories on the command line none were traversed.  The
shell could not expand the file glob and handed the literal "*.ldif"
to grep.  Grep tried to open "*.ldif" as a file and could not and
reported the error as fgrep: *.ldif No such file or directory.

When using -r it is common to specify . as the directory to grep

  fgrep -ri "cn: " .

Instead for doing file finding operations you should use find.  I
suggest this pattern.

  find . -name '*.ldif' -print0 | xargs -r0 grep "cn: "

This is an FAQ documented here.  Look for "Why doesn't rm -r *.pattern
recurse like it should?"


Hope that helps.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]