How to Clear the macOS CoreSpotlight Cache via Terminal

The Spotlight Daemon

Spotlight is the central nervous system of macOS search. When you press Command + Space and type a query, Spotlight instantly returns applications, documents, emails, and web results. To achieve this, a background daemon called mds (Metadata Server) and its worker process mdworker continuously crawl your hard drive, indexing the contents of every file into a massive SQLite database.

If this database becomes corrupted, the results are catastrophic. Spotlight might fail to find an application you just installed, or worse, the mds_stores process might get stuck in an infinite indexing loop, consuming 100% of your CPU, causing your Mac’s fans to run at maximum speed, and completely draining your battery in under an hour.

While Apple provides a graphical way to rebuild the index (by dragging your hard drive into the Spotlight Privacy tab and dragging it out again), this method frequently fails on deeply corrupted caches. To guarantee a complete purge and rebuild, you must use the Terminal.

Using the mdutil Command

Apple provides a dedicated command-line utility called mdutil specifically to manage the metadata stores.

Because the Spotlight index spans the entire system volume, you must execute these commands with elevated administrator privileges.

  1. Open the Terminal application.
  2. Execute the following command to completely erase the Spotlight database on the primary hard drive:
sudo mdutil -E /

Press Enter, type your Mac’s administrator password (the characters will remain invisible), and press Enter again.

The Terminal will output: /: Index will be rebuilt.

Disabling and Re-enabling the Indexer

Sometimes, simply erasing the index isn’t enough to kill a runaway mdworker process. You should forcefully turn off the indexing engine, clear the cache, and turn it back on.

Execute this sequence of commands:

# 1. Turn off Spotlight indexing for the main drive
sudo mdutil -i off /

# 2. Erase the cache database
sudo mdutil -E /

# 3. Turn Spotlight indexing back on
sudo mdutil -i on /

Verifying the Rebuild Status

The moment you turn the indexer back on, the mds daemon will begin crawling your SSD to rebuild the database from scratch.

If you press Command + Space and type a letter, you will see a progress bar that says “Indexing…”

You can also check the status directly from the Terminal:

mdutil -s /

The terminal will report /: Indexing enabled. If the CPU continues to run hot for the next hour, do not panic. The rebuilding process requires significant processing power to read and categorize every single document, photo, and email on your Mac. Once the progress bar finishes, your CPU usage will drop back to zero, and your search functionality will be fully restored.

Get the best tech tips delivered straight to your inbox.

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