From owner-freebsd-questions@FreeBSD.ORG Sat May 30 12:12:54 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 5AE9F1065703 for ; Sat, 30 May 2009 12:12:54 +0000 (UTC) (envelope-from mel.flynn+fbsd.questions@mailing.thruhere.net) Received: from mailhub.rachie.is-a-geek.net (rachie.is-a-geek.net [66.230.99.27]) by mx1.freebsd.org (Postfix) with ESMTP id 216878FC23 for ; Sat, 30 May 2009 12:12:53 +0000 (UTC) (envelope-from mel.flynn+fbsd.questions@mailing.thruhere.net) Received: from sarevok.dnr.servegame.org (mailhub.rachie.is-a-geek.net [192.168.2.11]) by mailhub.rachie.is-a-geek.net (Postfix) with ESMTP id A19CD7E837; Sat, 30 May 2009 04:12:52 -0800 (AKDT) From: Mel Flynn To: freebsd-questions@freebsd.org Date: Sat, 30 May 2009 14:12:50 +0200 User-Agent: KMail/1.11.3 (FreeBSD/8.0-CURRENT; KDE/4.2.3; i386; ; ) References: <80cddf609e38046ffa0ce3f2bdab235c.squirrel@relay.lc-words.com> <139b44430905300456x62bf9c0ybf46bcab6b64e25@mail.gmail.com> In-Reply-To: <139b44430905300456x62bf9c0ybf46bcab6b64e25@mail.gmail.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200905301412.50958.mel.flynn+fbsd.questions@mailing.thruhere.net> Cc: Zbigniew Szalbot , Valentin Bud 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 12:12:54 -0000 On Saturday 30 May 2009 13:56:22 Valentin Bud wrote: > 2009/5/30 Zbigniew Szalbot > > > >> 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. > > > > Ahhh - I use grep on daily basis. Now why didn't I think of it? I got so > > fixed on the idea of using find that I completely forgot about grep.... > > > > Sorry for the noise and thank you very much for your help! > > > > -- > > Zbigniew Szalbot > > > > _______________________________________________ > > freebsd-questions@freebsd.org mailing list > > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > > To unsubscribe, send any mail to " > > freebsd-questions-unsubscribe@freebsd.org" > > Hello Mr. Zbigniew Szalbot, > > You can use egrep -r * (grep -e) to search for specific text pattern while > you are in a directory with many sub directories. The output is nice > because it tells you the file in which the text pattern was found :). Discouraged because: - it's possible to hit maxarglen if the root directory has many subdirectories. - Will not search hidden directories in the root directory because of the shell glob - cannot be combined with other search criteria such as the file's timestamp. find . -type f -mtime 2 -exec grep '^Subject: \[SPAM\]' {} + will find all messages in a maildir modified within the last 2 minutes where the subject has been flagged as spam. I use + rather then ; so that one invocation for grep is done whenever maxarglen is hit (like if you used xargs(1)), rather then one grep per file. -- Mel