When should we enable the `locate` command on a Mac?
The locate
command in Bash is available besides find
to look for files, but it requires building a database. On a Mac, how useful is this and in what situation(s) should we enable it?
$ locate 'node_modules'
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.
Once created, according to the man page for locate, the database is updated, automatically, every day or week. I suppose it's one of the daily/weekly scripts that run automatically and that can be forced to run by the app OnyX. As to the difference between find and locate; since locate is said to be a "find filenames quickly" command, I suppose find doesn't use the database. So I'd create the database at your earliest convenience and then it'll get updated automatically in the background.