Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 214 down vote accepted

You missed a ; 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.

share|improve this answer
If you use the \; ending construct grep is passed one file at a time, so it doesn't display the file name by default, only the matched lines. To get a file list instead add use grep -ls inside of the find construct. – Caleb May 10 '11 at 6:55
find . -exec grep foo {} + will show you output like this ./dir/file.py:from foo import bar – s g Apr 17 '15 at 20:30
find . -exec grep foo {} \; will show you output like this from foo import bar – s g Apr 17 '15 at 20:31
find . -exec grep -l foo {} + will show you output like this ./dir/file.py – s g Apr 17 '15 at 20:32
find . -exec grep -l foo {} \; will show you output like this ./dir/file.py – s g Apr 17 '15 at 20:33

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
share|improve this answer
grep will choke if the expansion goes over ARG_MAX. -R will visit everything while using find one can more easily add primitives to exclude certain files (-name, etc) or not even visit subtrees (-prune). – Mel May 9 '11 at 23:58
Good points @Mel. My point was that in all likelihood the asking party was making things more complex than they needed to be by introducing find when grep could do the job, but in some cases it would be more effective to to use find to fine tine the file list before going out to grep. – Caleb May 10 '11 at 6:53
@Mel grep does not choke in such a case, exec does. – Chris Down Mar 26 '13 at 6:21
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.

share|improve this answer
The problem with xargs is that it expects its input to be quoted in a peculiar way that find doesn't produce. So find … | xargs … doesn't work if you have file names containing whitespace or \'". – Gilles May 10 '11 at 6:31
@Gilles You can get around that problem by using something like find . | xargs -n1 -iX grep "X" 'chrome' so that arguments are fed one at a time and quoted. Obviously this is a horribly inefficient way to handle this example, but for some situations it's nice. – Caleb May 10 '11 at 11:56
For completeness we should also mention the -i option for case insensitivity with 'grep'. Also there is -iname in find for case insensitivity. – Mathew May 10 '11 at 12:01
@Caleb: The only 100% reliable way to have xargs cope with Linux filenames is find ... -print0 | xargs -0, using NUL as separator. Alternative - xargs -d '\n' using newline as separator, 99% reliability. – grawity May 10 '11 at 20:18
I use this often, but it will fail for very long lists of filenames, at which point find -exec becomes the winner. – Spacemoose Jul 5 '15 at 9:08

To see list of files instead of lines:

grep -l "chrome" *


grep -r -l "chrome" .
share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.