Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 30 May 2009 12:13:28 +0200
From:      Erik Trulsson <ertr1013@student.uu.se>
To:        Zbigniew Szalbot <z.szalbot@lcwords.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: find and searching for specific expression in files
Message-ID:  <20090530101328.GA59991@owl.midgard.homeip.net>
In-Reply-To: <dd6b168d2af9ddbcfc52e5c0397e4d6a.squirrel@relay.lc-words.com>
References:  <dd6b168d2af9ddbcfc52e5c0397e4d6a.squirrel@relay.lc-words.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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).



-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090530101328.GA59991>