Using mdutil to reindex volumes for Spotlight on OS X
Over the last few months, I noticed an increasingly annoying issue on my MacBook concerning start-up performance with Spotlight, the built-in search tool for OS X. Since I started my exploratory Mac usage about two years ago, I quickly learnt that I could use Spotlight as a lightweight application launcher in favour of some more comprehensive packages available, i.e. Alfred, Quicksilver. Sadly, Spotlight became increasingly slow to load and to return valid results from files that were not modified recently after log-in.
I was not sure exactly what was the origin of this issue, but I suspected the metadata index from which Spotlight queries results was either corrupted or simply neglecting to index my Applications directory correctly. Thankfully, there exists a simple command line utility that allows you to erase the Spotlight index and toggle indexing, which will force Spotlight to rebuild it’s index: mdutil.
Note: mdutil requires administrator privileges to modify the Spotlight index, so do not forget to prefix the following commands with sudo or you’ll be misled by the returned messages from mdutil.
- Disable indexing:
mdutil -i off <path to volume> - Erase the existing Spotlight indexes:
mdutil -E <path to volume> - Enable indexing and wait for index to rebuild (this can be a slow process):
mdutil -i on <path to volume>
After running the aforementioned commands in that order, Spotlight began the slow process of rebuilding it’s index. Since this completed, I noticed that my results return a bit more quickly than previous and there does not seem to be as long of a wait to use Spotlight after log-in. Hopefully this procedure solves any similar issues you may be experiencing.