[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SOLVED] Re: find



Many thanks to all.

Stephen R Laniel wrote:
On Wed, Oct 26, 2005 at 02:30:10PM +0100, showroom@worldapart.com wrote:

I'm trying to find a word in a file using find.
I take a look at the man of find but...
All i see is to find files, perms, etc.
It's possible to find an word in a text file?
All i can do is this:
$find . -name *.c -print


The 'find' command doesn't actually look at the contents of
files. It can find you a file by filename, by date of
creation, but permissions and so forth, but it won't
actually look in the file. For that you need grep. If you
wanted to search inside all the files named '*.c' for the
string '#include', say, you'd do something like so:

find . -name '*.c' -exec grep -H '#include' '{}' \;

If you don't mind searching within *all* the files beneath
your current directory, you could use a much simpler
command:

grep -r '#include' .

'find' and 'grep' are perhaps the two most valuable tools in
the UNIX toolkit. They're definitely worth getting to know.




Reply to: