Trouble with my locate database... "database header corrupt"

I am getting errors when searching my locate database. I deleted and rebuilt but get the same errors.

$ locate -d $HOME/* fuse
locate: locate database header corrupt, bigram char outside 0, 32-127: -1


So I removed it and triggered the warning to check what the proper commands are to rebuild:


$ locate python

WARNING: The locate database (/var/db/locate.database) does not exist.
To create the database, run the following command:


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


Please be aware that the database can take some time to generate; once
the database has been created, this message will no longer appear.


Yet,,,, after it's done building I get the same error when running locate and using -d flag.


Is this a Gatekeeper/SIP issue? If so how do I whitelist the locate process?


UPDATE: When I run:

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


And look at active Daemons, this is listed. Yet it shows up as "stuck" and is "restricted" in Activity Monitor.





I read on this website that we should do things differently.


  1. create a central file name database excluding users' home directories
  2. create individual file name databases for directories and files in a user's home directory.



This is the default content of locate.rc

#
# /etc/locate.rc -  command script for updatedb(8)
#
# $FreeBSD: src/usr.bin/locate/locate/locate.rc,v 1.9 2005/08/22 08:22:48 cperciva Exp $


#
# All commented values are the defaults
#
# temp directory
#TMPDIR="/tmp"


# the actual database
#FCODES="/var/db/locate.database"


# directories to be put in the database
#SEARCHPATHS="/"


# directories unwanted in output
#PRUNEPATHS="/tmp /var/tmp"


# filesystems allowed. Beware: a non-listed filesystem will be pruned
# and if the SEARCHPATHS starts in such a filesystem locate will build
# an empty database.
#
# be careful if you add 'nfs'
#FILESYSTEMS="hfs ufs apfs"

Posted on Apr 19, 2021 12:45 PM

Reply
Question marked as Top-ranking reply

Posted on Apr 19, 2021 2:11 PM

I get the same error when I try the same command. It looks like your command is invalid, the "-d" parameter specifies a database, not a directory. Your shell would expand the * into every file in your home directory.


When I run locate without that parameter, I get the error about not having a database.


Maybe try giving the /usr/libexec/locate.updatedb tool Full Disk Access in System Preferences > Security & Privacy > Full Disk Access. You will have to restart the daemon.


Why not just use the "which" command instead?

2 replies
Question marked as Top-ranking reply

Apr 19, 2021 2:11 PM in response to johnnyjackhammer

I get the same error when I try the same command. It looks like your command is invalid, the "-d" parameter specifies a database, not a directory. Your shell would expand the * into every file in your home directory.


When I run locate without that parameter, I get the error about not having a database.


Maybe try giving the /usr/libexec/locate.updatedb tool Full Disk Access in System Preferences > Security & Privacy > Full Disk Access. You will have to restart the daemon.


Why not just use the "which" command instead?

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Trouble with my locate database... "database header corrupt"

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.