[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: using locate properly



On Tue, Oct 08, 2002 at 03:15:19PM +0200, Robert Wilhelm Land wrote:
...
> rland@MINI:~$ locate [Mm]uttrc
> ... no reaction.
> 
> Rereading the info gave me:
...snipped where you found out about metachars and quoting

> .....so I tried:
> 
> rland@MINI:~$ locate '[Mm]uttrc'
> rland@MINI:~$ locate "[Mm]uttrc"

> But:
> rland@MINI:~$ locate &pi0;[Mm]uttrc'

Does &pi0 denote a backtick?
Maybe it's time to RFM of bash about quoting?
...
> What has happened here?

You were so glad you found a solution that you forgot to read the rest:)
Really, if you had only read the next paragraph in locate's man page you
would have seen that patterns containing metachars are matched against
complete path names, so you should have specified a leading *, like:

  $ locate *[Mm]uttrc

(thanks to file globbling pecularities and the fact that in the current
directory no file matched the above pattern I could do without quoting
or escaping meta chars.  So I did, just to save a few keystrokes:)

In this playing with file globbling, quoting and meta chars it's good
to realise who is doing what.  The shell does the file globbling, i.e.
it tries to expand patterns on the commandline into file names to pass
on to the command specified at the start of the commandline.  When a
pattern doesn't match an existing file, the pattern is passed on `as is'.
The locate program on its turn treats its arguments *again* as file
globbling patterns, now to be matched against its file name database.

-- 
groetjes, carel



Reply to: