How to enable locate and queue the database to be built

command linecronfileslocate

On a new Ubuntu 10.4 instance, I tried to use the locate command only to receive the error

locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory

from using this command on other systems I'm guessing that this means the database has not yet been built (it is a fresh install). I believe it is supposed to run daily, but how would I queue it up to run immediately?

Also, how is "run daily" determined? If I have a box that I only turn on for an hour at a time will the database ever be built on it's own?

Best Answer

The cron job is defined in /etc/cron.daily/mlocate.

To run it immediately:

sudo updatedb

or better

sudo ionice -c3 updatedb

This is better because updatedb is set in the Idle I/O scheduling class, so that it do not disturb (from the I/O point of view) other applications. From ionice man page:

  -c class
          The scheduling class. 0 for none, 1 for real time, 2 for 
          best-effort, 3 for idle.

  ........................

  Idle   A program running with idle io priority will only get disk time
         when no other  program  has  asked  for disk io for a defined 
         grace period. The impact of idle io processes on normal system 
         activity should be zero. This scheduling class does not take a 
         priority argument. Presently, this scheduling class is permitted 
         for an ordinary user (since kernel 2.6.25).