find and searching for specific expression in files

Erik Trulsson ertr1013 at
Sat May 30 10:14:06 UTC 2009

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 at

More information about the freebsd-questions mailing list