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.

For example, I want to find all files in a directory that end in 'm' or 'sh'. The following works correctly:

find . -regex '.*.m' -o -regex '.*.sh'

But this fails:

find . -regex '.*.(m|sh)'

What am I doing wrong?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Just escaping hell:

find . -regex '.*.\(m\|sh\)

appears to work. I don't think there's much consensus whether regexp special chars need to be escaped or need to be unescaped between different tools.

share|improve this answer
3  
find(1) uses POSIX Basic regular expressions by default (and so does grep). Use the -E switch (BSD) or the -regextype posix-extended (GNU) to switch to the modern extended flavour –  hhaamu Feb 19 '12 at 20:26
    
Also see the final paragraph of re_format(7) for the differences between BRE and ERE: netbsd.gw.com/cgi-bin/man-cgi?re_format+7+NetBSD-current –  hhaamu Feb 19 '12 at 20:34
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.