A long-time reader asks the following question: “I use Spotlight all the time to search for files on my system. Usually it works, but sometimes it doesn’t. How can I fix this?”. Spotlight is an incredible tool that’s built-in to Mac OS X (if you don’t know what Spotlight is, click here to read more). It’s great for finding files, folders, images, PDFs… even for launching applications and doing simple math calculations or conversions.
Spotlight is so fast at searching for files on your system because it maintains a small database of your files in a single index file, which can be quickly searched. Occasionally, this index file can become corrupt, resulting in odd search behaviors. Here’s how to fix that problem.
In order to repair the index corruption so that Spotlight searches as designed, we need to rebuild your index. There are two ways to do this:
- The Drag-n-Drop Method
- The Command Line Method
The drag-n-drop method is done by opening System Preferences, then clicking the "Spotlight" button. Next, click on the “Privacy” tab, then click on the [+] button at the bottom to add your “Macintosh HD” drive to the list (if you want to only force a re-index on a specific folder, you can choose to add that folder to the list instead of the entire Macintosh HD volume). Once this is done, wait 30 seconds, then remove it from the list.
At this point, you’re probably asking “Why did I add it to the list to just remove it?”. By adding a folder or volume to the privacy list, we are telling Spotlight NOT to index that folder or volume. As a result, the information related to that folder or volume will be removed from the Spotlight index. When we remove it from the list, we are telling Spotlight to include it to the index again. As a result, it will force Spotlight to re-index that folder or volume. The re-indexing process usually takes anywhere from a minute to 30 minutes, depending on how many files are contained in that folder or on that drive.
The command line method (which gives you the same results as the above method) is done by opening the Terminal app and typing the following command at the prompt:
sudo mdutil -E /
Once you hit <enter>, you will be prompted to enter an Administrator password (we are, after all, running this command as an Administrator). After you have done this, the re-indexing process will begin.
If you want to perform a re-index on a specific folder or drive, omit the “/“ switch, and you will be prompted to specify a folder or drive volume.