2008-05-20

GnuWin32 find and missing argument for exec

Reminder on how to use -exec action in GnuWin32 find command in Windows cmd.exe. For example, if you want to find a string, the format is:

find . -type f -exec grep <pattern> {} ;

If you do any of the following, you can get this cryptic error message: find: missing argument to `-exec'

  • Put double-quote marks around the command:
    find . -type f -exec "grep <pattern> {} ;"
  • Don't leave a space between braces and semi-colon:
    find . -type f -exec "grep <pattern> {};"
  • Use Unix shell escape character:
    find . -type f -exec grep <pattern> {} \;

Finally, if all else fails and you lack time to investigate, use xargs:

find . -type f | xargs grep <pattern>

7 comments:

  1. Thank you. This is very helpful.

    ReplyDelete
  2. Very helpful. right on the money.

    ReplyDelete
  3. Excellent, very well explained

    ReplyDelete
  4. i love you, just spent an hour trying to sort this

    ReplyDelete
  5. try also:
    find . -type f -exec grep pattern "{}" ";"

    ReplyDelete