Shell – find utility does not recognize bracket notation

findquotingregular expressionshell

I've two files in the current folder:

submitWeb.m
submit.m

the following find does not show the two files:

find . -regex .*submit\(Web\)?\.m

But the above regex expression works fine in emacs buffer, i.e., search for the example strings in the emacs buffer using isearch-forward-regexp.

The default regextype for find is emacs.

But it seems that find consider \( as a left bracket in the filename, which differs from emacs regex syntax.

So is this a bug or my misunderstanding of find manpage?

Best Answer

It seems that the problem is \( is interpreted by the shell first.

For example, you got a file in the current directory named:

foo(.test

Then

ls foo\(.text

and

ls "foo(.text"

both work.

So, the following works:

find . -regex ".*submit\(Web\)?\.m"

EDIT:

Single quote also works here.

Difference between single quote and double quote, see this post: single quote vs double quote in bash

Related Question