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


I am getting errors when searching my locate database.

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



note that this broke when trying to manually update my db by

sudo ln -s /usr/libexec/locate.updatedb /usr/local/bin/updatedb


Then running:

sudo updatedb


MacBook Pro 16″

Posted on Jun 26, 2023 12:20 AM

Reply
Question marked as Top-ranking reply

Posted on Jun 26, 2023 12:26 AM

The error message indicates that there's a problem with the header of the database file, and a character in the bigram is outside the expected range of 0, 32-127.


The solution for me after some research was to go to the directory of the update db

Rebuild the locate database: The locate command relies on a database of files in your system. If this database becomes corrupt, you can rebuild it. On a Mac, you can do this by running the following command in your terminal:

cd /usr/libexec/

and then run

sudo /usr/libexec/locate.updatedb

Which rebuilt my locate database


NOTE that this can take a while and there isn't any progress bar so make sure to just wait till the command exists I think thats what was happening to me when I tried to update the db the first time I exited too early

Similar questions

4 replies
Question marked as Top-ranking reply

Jun 26, 2023 12:26 AM in response to ajamal1

The error message indicates that there's a problem with the header of the database file, and a character in the bigram is outside the expected range of 0, 32-127.


The solution for me after some research was to go to the directory of the update db

Rebuild the locate database: The locate command relies on a database of files in your system. If this database becomes corrupt, you can rebuild it. On a Mac, you can do this by running the following command in your terminal:

cd /usr/libexec/

and then run

sudo /usr/libexec/locate.updatedb

Which rebuilt my locate database


NOTE that this can take a while and there isn't any progress bar so make sure to just wait till the command exists I think thats what was happening to me when I tried to update the db the first time I exited too early

Jun 26, 2023 7:47 AM in response to ajamal1

I’d suggest using mdfind and its keyword syntax, rather than locate.


mdfind is the much more capable command line interface into Spotlight search.


Unlike locate, Spotlight (and mdfind) data is kept continuously updated. locate gets periodic (daily?) rebuilds.


Here’s a set of examples:

https://github.com/yuriskinfo/cheat-sheets/blob/master/cheat-sheets/macos-mdfind-examples-cheat-sheet.adoc


Or for those with entrenched finger memories:

alias locate=mdfind -name

Jun 26, 2023 10:17 AM in response to MrHoffman

I appreciate your reply Mr. Hoffman, I didn't even know you could assign aliases like that, it may have solved my problem! I agree that mdfind is far superior in that regard, my issue was that I have some apple script arrays written and executed through multiple python programs/classes that utilizes the locate command, the python code is extensive and integrates between Apple script executions and python library calls, in the end this code can do some low level terminal commands as well as other automation, the code needs some updating to use mdfind instead of locate, which is why I couldn't just use mdfind like I would on a terminal.

I still find it strange that there isn't a simple setting to adjust when the locate db updates.


For context by the way the reason Im doing this is Im very new to mac although I have utilized some linux in the past, I was big on AutoHotKey and other scripting on windows so I found the best way to do similar things is using apple script/Python and automating commands, in the end its all productivity software I build to help make things faster and less annoying.

Jun 26, 2023 10:48 AM in response to ajamal1

I prefer bash or zsh for scripting, and that can get to Python or whatever else, and can get to the Mac GUI via osascript.


By default, the locate database is updated weekly, and only when those automatic updates are enabled with the (one-shot) command:

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


Spotlight is updated as file system changes are made.


I use AppleScript when scripting GUI apps and not more generally, but have (personally) run into tooling limits with more general use. AppleScript has also not been a particular focus of Apple attention in many years. For some scripting requirements, Automator droplets can be very handy though, as can other similar mechanisms in other tools.

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.