0

I'm trying to do at search for lots of folders contains ex. Events.1900-1990.events. I don't want folders ex. with Events.2004, only folders contains the years from 1900 -> 1990.

The name Event can be anything, it could be birthdays, wars, etc..

I have tried something like this:

find . -type d -regex '*/[a-z][A-Z]/19+\[0-9]*' -print

But without finding anything

1 Answer 1

1
find . -type d '(' -name '*19[0-8][0-9]*' -o -name '*1990*' ')'

This would find any directory in or under the current directory whose name contains any of the numbers 1900 through to 1990. The test is split in two on the file name where the first tests for numbers between 1900 and 1989, and the second test is for 1990.

Regular expressions don't need to be used in this case. The patterns above are filename globbing patterns.

If you want to add a test for a filename suffix .events, then you can do that in two ways:

find . -type d -name '*.events' '(' -name '*19[0-8][0-9]*' -o -name '*1990*' ')' 

find . -type d '(' -name '*19[0-8][0-9]*.events' -o -name '*1990*.events' ')'

Your command will not find anything as a * at the start of a regular expression matches the character *. You also escape one of the [ in the expression, which makes it match the character [.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .