Getting globbing to work with `locate`

locatewildcards

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
/boot/grub/hwmatch.lua
/etc/alternatives/lua-compiler
/etc/alternatives/lua-compiler-manual
/etc/alternatives/lua-interpreter
/etc/alternatives/lua-manual

$ locate 'lua' | wc -l
560

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
/usr/lib/libipelua.so.7.0.10
/usr/lib/liblua5.1.so
/usr/lib/liblua5.1.so.0
/usr/lib/liblua5.1.so.0.0.0
/usr/lib/gtk-2.0/2.10.0/engines/libluaengine.so

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?

Best Answer

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

locate '*lua*so*'
Related Question