Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I use the locate command in Terminal regularly. When does its database get updated? On other systems, I could run updatedb as root to force it to update.

Note: I know using mdfind to search with spotlight is another option

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

The locate database is updated by the following cronjob:

/private/etc/periodic/weekly/310.locate

On Most Mac systems, Cron has been replaced by launchd, and you'll find that /etc/crontab doesn't exist. The schedule for this scheduled job is determined by launchd, and can be seen with one of the following commands:

% cat /System/Library/LaunchDaemons/com.apple.periodic-weekly.plist
    #### SNIP
<dict>
    <key>Hour</key>
    <integer>3</integer>
    <key>Minute</key>
    <integer>15</integer>
    <key>Weekday</key>
    <integer>6</integer>
</dict>

Or, something a little more user friendly:

% open /System/Library/LaunchDaemons/com.apple.periodic-weekly.plist

launchd will then run the jobs specified in /etc/periodic/{daily,weekly,monthly}/*, using this schedule.

share|improve this answer
1  
tl;dr version: Saturdays at 3:15 AM local time. –  Chealion Oct 6 '10 at 22:38
1  
Or if the mac is sleeping at 3:15 AM Saturday morning, when it wakes. –  bmike Jun 10 '11 at 0:02
    
Yet another way to see the contents of the plist: defaults read /System/Library/LaunchDaemons/com.apple.periodic-weekly –  Harald Hanche-Olsen Jun 10 '11 at 16:26
add comment

From the locate manpage:

FILES
 /var/db/locate.database          locate database
 /usr/libexec/locate.updatedb     Script to update the locate database
 /etc/periodic/weekly/310.locate  Script that starts the database rebuild

By default, the database is rebuilt weekly through launchd. You can run locate.updatedb manually to do the update.

share|improve this answer
2  
On most Mac systems, cron is replaced by launchd. There is no /etc/crontab by default, for example. That was moved to launchd. –  Stefan Lasiewski Oct 6 '10 at 17:33
    
@Stefan - Your right. I forgot about that change, which Apple did in Tiger. –  KeithB Oct 6 '10 at 18:13
add comment

sudo periodic weekly is the easiest way to kick it off the weekly script which will call the normal rebuild of the locate database.

As noted launchd will start this script Saturdays at 03:15 AM if the mac is running. If the mac is sleeping at that time, it will run when the mac wakes. It won't run if the mac is powered off at the magic moment.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.