1

I have a bunch of directories with numerical names, betwen 1 and 1,500 and I wanted to use the find command to find only these that are in range of 1,250 and 1,500, this regular expression should do that: [1][2-5][0-9][0-9] so Itried this command:

find . -regextype sed -regex "[1][2-5][0-9][0-9]"

But find finds nothing, am I doing something wrong?

1

From man 1 find [emphasis mine]:

-regex pattern
File name matches regular expression pattern. This is a match on the whole path, not a search. For example, to match a file named ./fubar3, you can use the regular expression .*bar. or .*b.*3, but not f.*r3.

So this will find something:

find . -regextype sed -regex ".*/1[2-5][0-9][0-9]"

Note [1][2-5][0-9][0-9] you used covers the range 1200-1599. [1] can be just 1 as in my example.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.