Update locatedb via cron

The locatedb database is used by the locate command in Ubuntu to quickly find files and directories on your system. It’s updated periodically using a cron job. Here’s how you can set up a cron job to update the locatedb database on Ubuntu:

  1. Open a terminal window.

  2. Edit the crontab for the root user. You can do this by running the following command:

    sudo crontab -e
    
  3. This will open the root user’s crontab file in your default text editor (usually nano or vim). Add the following line to the file:

    0 3 * * * updatedb
    

    This line tells the cron scheduler to run the updatedb command every day at 3:00 AM. You can adjust the schedule as needed.

  4. Save the file and exit your text editor.

  5. The updatedb command will now be executed daily to update the locatedb database, ensuring that it stays current.

Note:

  • The updatedb command is typically run as the root user because it needs access to all files on the system. This is why we use sudo crontab -e to edit the root user’s crontab.
  • Be cautious when modifying the crontab for the root user, as it can have significant system-wide effects. Make sure you understand the implications of the changes you make.

That’s it! You’ve set up a cron job to update the locatedb database on your Ubuntu system.