Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

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

share|improve this answer
    
Or put the regex in single quotes instead: find . -regex '.*submit\(Web\)?\.m' –  slm May 26 '13 at 1:44
    
@slm Yes, anyway, just prevent the shell from interpreting the \(. Edited. –  gongzhitaao May 26 '13 at 4:08
2  
A good rule of thumb is to quote everything in single quotes unless you specifically need the substitution behavior of double quotes. –  tripleee May 26 '13 at 11:28
    
@tripleee Thank for reminding. Edited. –  gongzhitaao May 26 '13 at 14:42
add comment

Your Answer

 
discard

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.