Find Command with Regex Quantifier {1,2}

bashfindregular expression

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.

Best Answer

You could try

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

or

find . \( -name "myfile[0-9][0-9]" -o -name "myfile[0-9]" \)
Related Question