Apple - macOS Mojave - locate not working

Amigo, I might start with launchctl:

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.locate.plist

Then check for any impediments to obtaining exclusive lock privilege on the nonexistent database:

sudo fuser -fu /private/var/db/locate.database
sudo lsof /private/var/db/locate.database

Then kill any process reported by either command. Next, run the db generator by hand, preceded by an opensnoop for debugging if something goes wrong. You will need to open a new terminal window ( command key - N shortcut, I believe ) and run opensnoop there, exiting it with a Control Key - c combo.

sudo opensnoop -cegx -f /private/var/db/locate.database 

Then over to your original window type:

sudo /usr/libexec/locate.updatedb

Remember to quit opensnoop with a cntrl-c in its window.

F.


I was using the MacBook for about three weeks and just put it to sleep everyday. For some unknown reason locate was not working. To solve the issue, it helped the classical "have you tried to turn it on and off?" After restart, it worked.

As already mentioned, locate is configured to update its database every Saturday, so it doesn't find any new file created before it updates. A workaround is to set the .plist file for everyday updates.

And as @mateusz-szlosek suggested, the command mdfind is more efficient and can find recently created files using the option -name.