# FreeBSD 9.1 locate / mlocate functionality



## splurben (May 12, 2013)

Coming from more of a Gentoo Linux background but becoming increasingly impressed with FreeBSD. I have searched and found very little about this. What do I install to get mlocate / locate functionality for keeping a database to make searching the filesystem faster?

Kirk


----------



## kpa (May 12, 2013)

There is locate(1) in the base system, no need to install anything. The database for it is updated by a periodic(8) script once a week. The script is named /etc/periodic/weekly/310.locate, you can run it manually as root to get the database updated immediately.


----------



## splurben (May 12, 2013)

*Zero-sized database, no other errors?*

Cool, thank you. So I invoked the weekly periodic object with no errors either on stdout or in /var/log/messages. The database isn't being initialised, I think. Couldn't find a log for periodic. Output below:

```
[krh@bsd-krh ~]$ sudo periodic weekly
Password:
[krh@bsd-krh ~]$
```


```
[krh@bsd-krh ~]$ ls -hl /etc/periodic/weekly/310.locate 
-rwxr-xr-x  1 root  wheel   626B Nov 27 11:31 /etc/periodic/weekly/310.locate
[krh@bsd-krh ~]$
```


```
[krh@bsd-krh ~]$ ls -hl /var/db/locate.database 
-rw-r--r--  1 nobody  wheel     0B Nov 27 11:31 /var/db/locate.database
[krh@bsd-krh ~]$
```


```
[krh@bsd-krh ~]$ locate testfile
locate: database too small: /var/db/locate.database
[krh@bsd-krh ~]$ sudo locate testfile
Password:
locate: database too small: /var/db/locate.database
[krh@bsd-krh ~]$
```


----------



## kpa (May 12, 2013)

Run the /etc/periodic/weekly/310.locate script with `sh -x` and with script(1) to get a log file to see if there's anything going wrong:

`script 310.locate.log sh -x /etc/periodic/weekly/310.locate`


----------



## wblock@ (May 12, 2013)

When all you want is to rebuild the database, it's best to just run /etc/periodic/weekly/310.locate directly.  The weekly job does other things and may be configured to not update the database.  Regarding that, please show the contents of /etc/rc.conf and /etc/periodic.conf (if present).

Is this an ordinary version of FreeBSD or a specialized distribution?


----------



## splurben (May 13, 2013)

Okay, I'm currently on PC-BSD. But as I mainly use Gentoo Linux, I'm more interested in using ports in FreeBSD. I just wanted to get a feel for it. I'm thinking I'll build a full FreeBSD system now.

After using @kpa's script(1) command to get a log. I found that PC-BSD's base configuration disables locate weekly, 
	
	



```
weekly_locate_enable="NO"
```
 in periodic.conf; thank you @wblock@ and @kph - issue sorted. I changed "NO" to "YES" and voila.

I now have a locate(1)] database. I did post on PC-BSD's forums but didn't get an answer, which is why I brought it back to FreeBSD's forums.

Cheers,

Kirk


----------

