Where is my.cnf? Use locate and mdfind

If you like me have trouble remebering the path to config files, locate is a wonderful little utility. The locate command is a standard and widely-used tool on most Unix systems for finding filenames which match a given pattern.

1. First enable the locate service

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

2. Wait

$: locate my.cnf

/Users/janne/.my.cnf
/usr/local/Cellar/[email protected]/5.7.24/.bottle/etc/my.cnf
/usr/local/etc/my.cnf
/usr/local/etc/my.cnf.default

Also, Apple supplies mdfind, which searches the Spotlight metadata store. The man page describes a number of options, most usefully

-name for names only (the default search is for name or content, just like Spotlight) -onlyin for limiting the search to specific directories -live to initiate live updating of search results

It is also possible to restrict the search to specific fields (keys) of the metadata store.

The results are not the same as locate, but can be usable:

$: mdfind my.cnf -name

/usr/local/etc/my.cnf
/usr/local/etc/my.cnf.default