How to Completely Rebuild the Spotlight Search Index via Terminal in macOS

Spotlight is the central nervous system of macOS. Pressing Command + Space allows you to launch apps, find buried PDF documents, and perform calculations instantly. However, the Spotlight index can occasionally become corrupted. When this happens, searches will return blank results, specific file types will mysteriously vanish from your queries, or your Mac’s fans will spin up as the mdworker process gets stuck in an infinite indexing loop.

The standard Apple troubleshooting advice is to open System Settings, drag your entire hard drive into the Spotlight “Privacy” list, and then remove it to force a re-index. This GUI method is notoriously unreliable. The most effective, professional way to forcibly purge and rebuild the Spotlight database from scratch is by using the mdutil (Metadata Utility) command in Terminal.

Step 1: Purge the Corrupted Index

Before we can build a fresh index, we must completely eradicate the corrupted one.

  1. Open the Terminal app (located in Applications > Utilities, or search for it via Launchpad).
  2. Type the following command to completely disable Spotlight indexing on your main hard drive:
    sudo mdutil -i off /
  3. Press Return. Because you are using sudo, you will be prompted to enter your Mac login password. (The characters will not appear on screen as you type; this is normal). Press Return again.
  4. Next, we will force the system to delete the hidden .Spotlight-V100 database folder where the corrupted data lives. Type:
    sudo mdutil -E /
  5. Press Return. You should see a message confirming that the index will be rebuilt.

Step 2: Restart the Indexing Service

Now that the old database is completely wiped from your hard drive, we need to turn the Spotlight service back on so it can begin cataloguing your files anew.

  1. In the Terminal, type the following command to turn indexing back on:
    sudo mdutil -i on /
  2. Press Return. You should see a confirmation message stating: “Indexing enabled.”

How to Check the Rebuild Progress

Rebuilding the index for an entire hard drive is a massive computational task. Depending on the size of your drive and the speed of your Mac’s processor, this process can take anywhere from a few minutes to several hours.

You can visually confirm that the rebuild is happening:

  1. Click the Spotlight magnifying glass icon in the top right corner of your menu bar (or press Command + Space).
  2. Type any word, like “Apple”.
  3. A progress bar will appear in the Spotlight window stating “Indexing…” along with an estimated time remaining.

During this time, your Mac may run slightly warmer and slower than usual. It is highly recommended that you leave your Mac plugged into wall power and allow it to finish the process uninterrupted. Once the progress bar disappears, your Spotlight search will be lightning-fast and perfectly accurate once again.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.