This output is rather self-explanatory:

XXXXX@debianvirtualbox:~$ locate -r "^/var/lib/tomcat[0-9]/.*" -l 10
jakub@maredadebianvirtualbox:~$ locate -r "^/var/lib/tomcat[0-9]{1,2}/.*" -l 10

I am trying to list first ten (-l 10) entries matching tomcat installation directory. If I just use [0-9] it properly matches tomcat8, however if I add a quantifier [0-9]{1,2} it matches nothing. Same goes for quantifiers + and ?, however * seems to work fine and so does this expression:


Why this happens and what's a good workaround?

1 Answer 1


Try --regex (without a 'p') rather than -r (aka --regexp). This tells locate to use extended regexps rather than basic.

locate --regex "^/var/lib/tomcat[0-9]{1,2}/" -l 10 

alternatively, escape { and } with \ to make them special in basic regex.

  • BTW, the above applies to mlocate's version of locate. I can't remember if it also applies to GNU locate from findutils, I haven't used anything other than mlocate for years.
    – cas
    Oct 2, 2015 at 7:58
  • Yeah, it works even with normal locate, thanks. Oct 2, 2015 at 8:06
  • GNU locate has a --regextype option to specify the type of regular expression. gnu.org/software/findutils/manual/html_mono/…
    – cas
    Oct 2, 2015 at 8:06

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.