# Locate DB



## Barney (Jul 26, 2020)

What is the "official" proper way to update the locate DB? If you run locate.updatedb as root, it scolds you to not run it as root. Running it as a user yields:


```
/usr/libexec/locate.updatedb: cannot create /var/db/locate.database: Permission denied
```


----------



## Mjölnir (Jul 26, 2020)

Barney said:


> What is the "official" proper way to update the locate DB?


`/etc/periodic/weekly/310.locate` or `periodic weekly 310.locate`


> ```
> /usr/libexec/locate.updatedb: cannot create /var/db/locate.database: Permission denied
> ```


Run as _root_.  I.e. precede sudo(8) or runas(8) to the above commands, or log in as root, e.g. invoke the command `su -`.


----------



## ralphbsz (Jul 26, 2020)

Even easier: Go into /etc/periodic.conf.local, and make sure weekly_locate_enable is set to true. Then it will automatically get updated once a week. I have actually a created a new entry in periodic/daily/320.locate, which is simply a copy of the weekly one, and disabled the weekly one; like that my locate is never older than a day.


----------



## Barney (Oct 24, 2020)

The point here is that I need to update is manually; like when I mount another disk and want to index what's on the disk. Or when I add some stuff to a system and want to update locate right away


----------



## ralphbsz (Oct 24, 2020)

If you want to manually run the database update once: /usr/libexec/locate.updatedb. Read the man page for locate.updatedb first, and look in /etc/periodic/.../320.locate, which will show you examples of the command line arguments.


----------



## tingo (Oct 24, 2020)

If you just want to update manually, you can also just run the periodic scripts manually:
`# /etc/periodic/weekly/310.locate`


----------



## Barney (Oct 27, 2020)

Grrrrr.


ralphbsz said:


> If you want to manually run the database update once: /usr/libexec/locate.updatedb. Read the man page for locate.updatedb first, and look in /etc/periodic/.../320.locate, which will show you examples of the command line arguments.


The OP points out the problem with running locate.updatedb; regular users don't have permission to create the db because its owned by nobody so only root and nobody can update it.


----------



## ralphbsz (Oct 27, 2020)

Oops, sorry, missed that completely. You can not run it is a regular user, that's correct. You can run it as root, but you will get a warning, and the warning makes sense. You can run it as user nobody (example how to do it is in the 310.locate script, not 320 as I wrote, that was a typo).


----------

