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

I have been trying to create a find command string that will find all files that end with a number 1-99 but exclude all others.

e.g. I want to find myfile1 myfile99 but not myfile456 and not myfilebackup

The regex I'm thinking of is myfile[1-9]{1,2} but I can't get this to work with find.

find . -regex '.*myfile[0-9]{1,2}' OR find . -iname 'myfile[0-9]{1,2}'

From what I can see it's the {1,2} part that is not working.

(by the way can you use -name -regex interchangably?)

Any help appreciated.

share|improve this question
-iname (and -name) use globs, which do not have this syntax. – l0b0 Mar 7 '13 at 13:51
up vote 6 down vote accepted

You could try

find . -regex '.*myfile[0-9][0-9]?'


find . -\( -name "myfile[0-9][0-9]" -o -name "myfile[0-9]" \)
share|improve this answer
Thanks - the first line is working for me. I had tried this with -iname but I don't think it supports the syntax or else I'm doing something wrong. – Lukas88 Mar 7 '13 at 14:16

If you have GNU find, you can use another regular expression type:

find . -regextype sed -regex '.*myfile[0-9]\{1,2\}'

According to GNU find uses a neutered Emacs regular expression syntax by default - Emacs supports \{from,to\} syntax, but at least GNU find doesn't support it.

Strangely, the reference manual doesn't include a section on the sed regular expression syntax, so who knows which parts of it are supported.

share|improve this answer
Cheers for this tip. Very useful to know. – Lukas88 Mar 7 '13 at 14:17

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.