How to run find -exec?

You missed a ; (escaped here as \; to prevent the shell from interpreting it) or a + and a {}:

find . -exec grep chrome {} \;

or

find . -exec grep chrome {} +

find will execute grep and will substitute {} with the filename(s) found. The difference between ; and + is that with ; a single grep command for each file is executed whereas with + as many files as possible are given as parameters to grep at once.


You don't need to use find for this at all; grep is able to handle opening the files either from a glob list of everything in the current directory:

grep chrome *

...or even recursively for folder and everything under it:

grep chrome . -R

find . | xargs grep 'chrome'

you can also do:

find . | xargs grep 'chrome' -ls

The first shows you the lines in the files, the second just lists the files.

Caleb's option is neater, fewer keystrokes.

Tags:

Find