0
  • This works fine: find . -name "skr[0-9][0-9][0-9][0-9][0-9].rtf" -type f

  • This does not work: find . -name "skr[0-9]{5}.rtf" -type f

Could anyone please explain and give me something similar to second version of the command.

2
  • There is not a single find command. Do you mean specifically GNU find? Commented Dec 29, 2014 at 21:16
  • yes, sorry i should have mentioned.. Commented Dec 29, 2014 at 21:17

1 Answer 1

2

the {5} is a syntax from extended regular expressions not from shell globbing. It is not valid with -name.

You can use -regex instead of -name with some find versions (GNU). In that case your pattern have to match the whole path, be careful with * and ? and . as they have different meanings in regular expressions.

The repetition count syntax is part of "extended" RE, so you need to use -E (with find variants which actually support it):

find -E . -regex '.+/skr[0-9]{5}\.rtf' -type f

On Mac you need to install GNU findtools if you want such comfort:

brew install findutils --default-names

On some systems you can try gfind instead of find.

Sign up to request clarification or add additional context in comments.

4 Comments

Could you please suggest some command similar to second version?
could you explain -regex usage in context of this example, i am newbie to linux commands that's why asking.
@user2132128 Well, as a newbie its best to forget about REs :) I added the example which works, as you can see it is not shorter as your initial correct version, so don't bother... (if you are curious check out a regex tutorial and keep in mind that ".+/" means "one or more characters ending with slash.
@user2132128 i typically read man or info pages. There is a good O'Reily Book on Mastering Regular Expressions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.