I'm using Mac 10.5.6. When I fire up my terminal, navigate to a
certain directory, and then execute this command
ocho:webapp dalvarado$ locate myco-galc-capitol-tours-webapp.war
ocho:webapp dalvarado$
I get no results back. But if I run ...
ocho:webapp dalvarado$ find . -name "*.war"
./target/myco-galc-capitol-tours-webapp-1.0-SNAPSHOT.war
./target/myco-galc-capitol-tours-webapp.war
You can see that the file I was searching for comes back as the second
result. So why didn't locate tell me where it was? Or should I be
using a different command?
- Dave
The locate command takes a "pattern" to match, which implies that it
uses regular expression pattern matching when searching the database(s)
for your search query. I've been familiar with, but far from expert at,
regular expressions for years, so I can't say with certainty what's
wrong. But I'm guessing that the special characters (those dashes) are
causing some grief. Had you tried typing "locate capitol" you should've
gotten back a list of every file and folder from the default locate
database with that string in its name.
--
Steve W. Jackson
Montgomery, Alabama
I just tried "locate capitol" but that returned no results, even
though I confirmed there are files matching that pattern (using the
find command). - Dave
> I just tried "locate capitol" but that returned no results, even
> though I confirmed there are files matching that pattern (using the
> find command). - Dave
is the locate database up to date?
The man page can be helpful, though I don't know if it addresses your
issues. There are two issues mentioned in the man page:
1) locate doesn't search the file system. It searches a database
(updated periodically, but what the period is can vary from system
to system). So the database can be expected to be somewhat out of
date at any given time.
2) When the database is created, it is run by user "nobody" which
means it will skip directories not readable by that user, at
least.
Assuming, of course, that he runs "updatedb" as root occasionally, or
has a cron script to do it for him...
-- Ron Bruck
That leads me to my next question ... where is the locate db update
controlled? Do I need to set up a cron or is this set up in System
Preferences or somewhere similar? - Dave
See 'man locate' and 'locate -S' for more info. The locate database is
in /var/db/locate.database. The command to schedule regular updates is:
sudo launchctl load -w
/System/Library/LaunchDaemons/com.apple.locate.plist
(according to 'locate -S')
--
Jim Gibson
> > Assuming, of course, that he runs "updatedb" as root occasionally, or
> > has a cron script to do it for him...
> >
> That leads me to my next question ... where is the locate db update
> controlled? Do I need to set up a cron or is this set up in System
> Preferences or somewhere similar? - Dave
In 10.5: .private/var/db/locate.database
(I found this with EasyFind ;) )
As I understand it, the weekly maintenance script updates
locate.database.
OR there is a handy little GUI front end for locate called Locator which
will do it on command.
I don't see that file on 10.5.8 (I'll have a more thorough dig later).
An easy way to rebuild the locate database (e.g. after adding a large
number of files) is
sudo periodic weekly
This will of course do other weekly stuff such as rotating your logs as
well.
--
Paul Sture
> sudo periodic weekly
Under Leopard, it was fairly easy to get updatedb to run as root.
It is very useful to have a quick search of all files and directories
on one's own machine.
I tried and failed to do this under Snow Leopard ( OS X10.6).
Anyone have the recipe?