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

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
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
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

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.