I'm on Ubuntu 11.04, where I have:

$ locate --version
mlocate 0.23.1 [...]

The man locate page says:

If --regex is not specified, PATTERNs can contain globbing characters. If any PATTERN contains no globbing characters, locate behaves as if the pattern were *PATTERN*.

OK, so to do a little test: first, just searching for 'lua' works - but returns a ton (500+) of results:

$ locate 'lua' | head -5

$ locate 'lua' | wc -l

I want to search for .so files with lua in the filename, so I try this as an attempt to use a globbing pattern:

$ locate 'lua*so*'

Nothing, 0 results. So I'm trying with a regex:

$ locate --regex 'lua.*so.*' | head -5

Well, this works - so it is good enough.

But what puzzles me is this - if the man page says globbing is supported when not using regex, how should I format my glob pattern to have it work?


Your glob will only match if the name starts with lua. Try this glob:

locate '*lua*so*'
  • Many thanks for that, @PM2Ring - I guess when I saw that the --regex worked without a starting *, I expected the glob would too, but that wasn't correct. Your glob works just fine - cheers! – sdaau Jan 24 '15 at 6:10
  • @sdaau: No worries. Yeah, the regex matches if a substring of the data matches your regex pattern, unless you explicitly use the ^ start of line anchor in your regex. But a glob has to match the whole thing. – PM 2Ring Jan 24 '15 at 6:17
  • 1
    I guess it should be mentioned for future readers of this question that if you don't quote the glob pattern (either with single or double quotes) then the shell itself will expand the glob to match files in the current directory and pass all those filenames to locate; this is generally not what you want here. :) – PM 2Ring Jan 24 '15 at 6:29
  • That feels almost like a bug to me... at least in the man page. Ok, theoretically, it's correctly documented - but this is not about a math paper. It needs to be practically correct. (The default matching can not be changed, of course - to fix it in the code would need a new option - does not sound sensible. But it's worth adding a line to the man page.) [note to self: report as bug] – Volker Siegel May 19 '15 at 20:26

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.