From owner-freebsd-hackers Tue Jan 23 09:51:51 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id JAA05760 for hackers-outgoing; Tue, 23 Jan 1996 09:51:51 -0800 (PST) Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.211]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id JAA05755 for ; Tue, 23 Jan 1996 09:51:47 -0800 (PST) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id KAA17822; Tue, 23 Jan 1996 10:34:44 -0700 From: Terry Lambert Message-Id: <199601231734.KAA17822@phaeton.artisoft.com> Subject: Re: recursive grep To: jmacd@CS.Berkeley.EDU (Josh MacDonald) Date: Tue, 23 Jan 1996 10:34:44 -0700 (MST) Cc: imp@village.org, wosch@cs.tu-berlin.de, hackers@FreeBSD.org In-Reply-To: <199601230131.RAA11361@paris.CS.Berkeley.EDU> from "Josh MacDonald" at Jan 22, 96 05:31:37 pm X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@FreeBSD.org Precedence: bulk > > : I would like add options for recursive searching > > : (grep -R foo /usr/include). > > > > find /usr/local | xargs grep foo > > > > Why do we need another wart on grep? Especially when what you may > > want is find /usr/local -name \*f.h | xargs grep foo :-) > > and why do we need an extra pipe, either? > > find /usr/include -name \*f.h -exec grep foo {} /dev/null \; The GNU derived find doesn't flush its output, so if you were to pipe it at that point (and use -print instead of a "/dev/null" argument to get the name), you would have your output screwed. The use of xargs causes one invocation of grep for a potentially large number of files, once per command line length limit, so it will execute it several times for an obscene number of files. Typically, you *will* want to use the "/dev/null" trick to get grep to spit out the name in case the last exec by xargs is on one file (otherwise the last one will be missing its file name). So: find /usr/local - print | xargs grep foo /dev/null ...use of -print is suggested in case of some older "finds" that do not put out anything by default (POSIX compliance discrepancy). Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.