locate command does not work on mac terminal
I'm working on Mac (Catalina, 10.15.7) and want to use the locate <...>
-command.
After typing locate ...
it suggested me the following, which I did.
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.
After creating the database, I wanted to perform the locate
-command.
This didn't work as expected. Instead this came up:
locate: locate database header corrupt, bigram char outside 0, 32-127: -1
What can I do to fix this? Thank you so much for your help.
You can try to delete (or move) the locatedb file, e.g. mv /var/db/locate.database /var/db/locate.database.backup
and then regenerate the database from scratch using /usr/libexec/locate.updatedb
. You will need to use sudo
for these commands:
sudo mv /var/db/locate.database /var/db/locate.database.backup
sudo /usr/libexec/locate.updatedb