From owner-freebsd-questions@FreeBSD.ORG Sat May 30 10:14:05 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D17EC106564A for ; Sat, 30 May 2009 10:14:05 +0000 (UTC) (envelope-from erikt@midgard.homeip.net) Received: from ch-smtp02.sth.basefarm.net (ch-smtp02.sth.basefarm.net [80.76.149.213]) by mx1.freebsd.org (Postfix) with ESMTP id 8BF718FC15 for ; Sat, 30 May 2009 10:14:05 +0000 (UTC) (envelope-from erikt@midgard.homeip.net) Received: from c83-255-48-78.bredband.comhem.se ([83.255.48.78]:61283 helo=falcon.midgard.homeip.net) by ch-smtp02.sth.basefarm.net with esmtp (Exim 4.69) (envelope-from ) id 1MALZD-0001yV-90 for freebsd-questions@freebsd.org; Sat, 30 May 2009 12:13:33 +0200 Received: (qmail 63721 invoked from network); 30 May 2009 12:13:28 +0200 Received: from owl.midgard.homeip.net (10.1.5.7) by falcon.midgard.homeip.net with ESMTP; 30 May 2009 12:13:28 +0200 Received: (qmail 60067 invoked by uid 1001); 30 May 2009 12:13:28 +0200 Date: Sat, 30 May 2009 12:13:28 +0200 From: Erik Trulsson To: Zbigniew Szalbot Message-ID: <20090530101328.GA59991@owl.midgard.homeip.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.19 (2009-01-05) X-Originating-IP: 83.255.48.78 X-Scan-Result: No virus found in message 1MALZD-0001yV-90. X-Scan-Signature: ch-smtp02.sth.basefarm.net 1MALZD-0001yV-90 f47837100d2d787ec3b0d1ab5ad77d37 Cc: freebsd-questions@freebsd.org Subject: Re: find and searching for specific expression in files X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 30 May 2009 10:14:06 -0000 On Sat, May 30, 2009 at 11:25:12AM +0200, Zbigniew Szalbot wrote: > Hello, > > Can you please give me a hint how to use find to search for a specific > text within files? Generally, you don't - find(1) does not examine the contents of files by itself, just their directory information. You normally use grep(1) to search within a file. > > I am using find in the following manner: > > find /path/to/files/ -mtime -2 -ls |less > to find files which have been recently modified. But I would like to > extend the search to find specific expression within files. -name is used > to specify file name. How can I search for strings within text? > > It is probably in the man but I somehow overlook it. :( > > Thank you very much in advance! I guess you could use the '-exec' expression in find(1) to execute grep(1) to search for a string in the files examined. Or you could use the output of find(1) as a list of files that are given as arguments to grep(1). -- Erik Trulsson ertr1013@student.uu.se