[Wylug-help] locate (Was: RAID, mdadm and df)
Smylers
Smylers at stripey.com
Fri Sep 24 14:45:32 UTC 2010
John Hodrien writes:
> On Fri, 24 Sep 2010, Smylers wrote:
>
> > However, I think you got lucky that the above command worked!
>
> Right you are. I always tend to be a little fast and loose with
> playing with locate, as it rarely matters when you get it wrong ;)
Quite. And if your first stab at it happened to give the answer you were
looking for, that's great.
Aiming to be lucky is an entirely reasonable strategy: if you're lucky
often enough then it's faster to guess, sometimes be wrong and require
further guesses, than to spend time being right.
But I am grateful that, however inadvertently, you prodded me into
learning locate properly.
The tricksy bit turns out to be that when matching patterns (that is
without -r), locate will pretend you put a "*" at the beginning and end
of your pattern, unless you've put any wildcards in the pattern, in
which case it will leave it alone.
In otherwords, locate mainly does substring matching. But if you use any
wildcards then it's doing whole-filename matching, so you need to put
"*"s in there yourself to get substrings.
And * isn't quite like in the shell, because it can match any character,
including /s.
(I am mostly typing this out for my own benefit, in the hope that I'll
retain the knowledge. Or at least remember that I wrote this and to
search the Wylug archives the next time I'm struggling to construct an
appropriate locate command.)
Smylers
More information about the Wylug-help
mailing list