Rebuilding Spotlight’s Index on OS X (Manually)

After doing a number of disk clean up and optimizations, I found myself in the circumstance of OS X’s spotlight returning no results. Whether I searched for a keyword in Mail, or by Spotlight using Command-Space, I got no results backs - just an empty list for my troubles.

It turns out there’s a neat utility out there called Rebuild Spotlight Index 2.7 that does all the grunt work for you. Problem is, it didn’t work for me.

What’s going on is actually fairly trivial, and it’s possible to simply do everything via the command line.

The metadata utilities need to run as root, so to see what your drive is up to, you’d enter something like: sudo mdutil -s /

This shows the status on the root volume.

To turn indexing on for a volume, you enter: sudo mdutil -i on /

And, to force Spotlight to rebuild its index, you simply erase the master copy of the metadata stores on the volume like this: sudo mdutil -E /

However, while I did all this, Spotlight was still not building the indexed for me.

Here’s how I solved it, using just the Terminal.
First, I wanted to see the schema file, so I printed it out using to the standard input using: sudo mdimport -X

At the bottom of the schema listing, I say a reference to a schemaLocation, and took a shot in the dark that perhaps that Spotlight’s index rebuilding needed to check data against its schema before it would start. To do that, it might need network access, if not back to the local machine.

And, for good measure, I went to check the date/timestamp on the Spotlight directory using: sudo ls -la /.Spotlight*

While most of the files had the timestamp of when I tried to delete the index, not all the files had the current date and time. Additionally, the file sizes were not growing, a good indication the index was not being rebuilt.

Thinking to myself, “what could be causing network traffic, even internally, not to be working”, I realized that I had just rebooted and PeerGuardian2 was currently active and blocking traffic. This is a great tool for blocking malware and unwanted network visitors, but occasionally it gets in the way. So, I turned it off.

Then, I did the following commands to ensure indexing was on, the spotlight metastore was really gone, and that I wanted it rebuilt:
sudo mdutil -i on /
rm -rf /.Spotlight*
sudo mdutil -E /

The moment I did the last command, this time the system sprung to life, the directory /.Spotlight-V100 was created, and the files inside it were growing quickly. Spotlight on the toolbar showed a progress bar, indicating the system would be done indexing in a bit. The big difference? I turned off the network traffic blocker for a moment.

6 Responses to “Rebuilding Spotlight’s Index on OS X (Manually)”

  1. Mugur Baloiu Says:

    Thanks for the tip.
    This was very helpful for my external hard drive on OSX Leopard. I had this issue - after the upgrade on Leopard, Spotlight was returning 0 results on a search to the external drive. It was so frustrating because it was perfectly working before Leopard.

    I am glad I could turn indexing on for my volume with this command:
    sudo mdutil -i on /

  2. David Livingstone Says:

    Thanks also. Can’t remember BASH syntax, so this helped step through the process with a new Leopard Server X install. It’s now indexing and I can go to bed.

  3. Tim Gibbons Says:

    You can force Spotlight to rebuild its database by adding the affected disk to the Spotlight Privacy exclusions in System Preferences, closing System Preferences, then removing it from the exclusion list. Spotlight will begin rebuilding the Spotlight database immediately. This may take a while!

  4. Oliver Lu Says:

    Another way to do it semi-automatically is with “Maintenance”, an Automator Apple Script. (It also does other stuff, like repair permissions and clean out caches.)

    It’s free and available through Apple (so presumably it’s safe):

    http://www.apple.com/downloads/macosx/automator/maintenance.html

  5. Dan Z Says:

    i had spent a while troubleshooting spotlight and finally this worked! changing the options within spotlight preferences had done nothing! i had to use the terminal as above, except my second command also required a preceding sudo as follows:

    sudo mdutil -i on /
    sudo rm -rf /.Spotlight*
    sudo mdutil -E /

    hope this helps others out there with the same problem. my leopard was installed as a generic image by my university as I used the mbpro only for the summer, and i hated how it never worked

  6. Pope Says:

    Thank you for this! The TimeMachine on my server went down, and I’ve been freaking out trying to get it to work again. The server has a lot of important stuff on it, and I hated it not being backed up properly.

    You’re a saint.

Leave a Reply


Bad Behavior has blocked 2519 access attempts in the last 7 days.