Problem running find: missing argument to `-exec'

I’d like to find the files in the current directory that contain the text “chrome”.

$ find . -exec grep chrome
find: missing argument to `-exec'

What am I doing wrong?

Asked By: ripper234


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
Answered By: Caleb

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

find . -exec grep chrome {} ;


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.

Answered By: bmk
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.

Answered By: Mathew

To see list of files instead of lines:

grep -l "chrome" *


grep -r -l "chrome" .
Answered By: mateusz.szymborski

Find is one way and you can try the_silver_searcher then all you need to do is

ag chrome

It will search chrome in all files (include sub directories) and it is faster than find

Answered By: Ask and Learn

Here’s an example of how I usually use find/exec…

find  . -name "*.py" -print -exec fgrep hello {} ;

This searches recursively for all .py files, and for each
file print(s) out the filename and fgrep’s for ‘hello’ on
that (for each) file. Output looks like (just ran one

print "hello"
print "hello again"
Answered By: jon
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.