Reindex Spotlight from the Command Line

Feb 2, 2012 - 3 Comments

spacer Spotlight is generally very good at keeping a valid index of a drives contents up to date, but if you’ve recently restored a drive or had to delete the Spotlight index for one reason or another, you may need to reindex the drive manually. This is easy from the Spotlight control panel, and can also be achieved through the command line as we’ll demonstrate.

Reindexing Spotlight from the Command Line

Reindexing Spotlight from the command line is done with the mdutil tool, first launch Terminal and then type:

sudo mdutil -E /

This will reindex every mounted volume on the Mac, including hard drives, disk images, external drives, etc. Specific drives can be chosen by pointing to them in /Volumes/, to only rebuild the primary Macintosh HD:

sudo mdutil -E /Volumes/Macintosh\ HD/

To reindex an external drive named “External” the command would be:

sudo mdutil -E /Volumes/External/

Use of the mdutil command will spin up mds and mdworker processes as Spotlight goes to work.

Individually Reindexing Selected Files
In rare cases, Spotlight can miss a file during index, so rather than reindex an entire drive you can also manually add an individual file to the search index with the mdimport command:

mdimport /path/to/file

The mdimport command can be used on directories as well.

Related articles:

  • Rebuild the Spotlight Index
  • Six useful Spotlight keystrokes
  • How to completely disable Spotlight
  • How to Disable (or Enable) Spotlight in Mac OS X Lion
Posted by: Paul Horowitz in Command Line, Mac OS X, Tips & Tricks

3 Comments

» Comments RSS Feed

  1. 911 says:
    February 2, 2012 at 7:04 pm

    Serious question. I see these posts on here quite often, do this or that from the command line.. Hmm. Do people actually do this?

    Reply
    • Teddster says:
      February 3, 2012 at 12:04 am

      Yes of course. It’s often quicker and more specific for advanced users, but the CLI gets a lot of use for sysadmins and others too. SSH in, rebuild clients Spotlight, etc. Remote administration. etc

      Reply
  2. Michael Rygaard says:
    February 3, 2012 at 12:54 am

    I still use Quicksilver, its still faster, and finds more.
    also it can find 2 names pr file.
    say you use Handbrake – but ½ of the time cant rember that strange name and rename it to “video converter and DVD ripper” then Quicksilver will find it on both the new and the old name.

    Reply

Leave a Reply

Click here to cancel reply.

Previous: Web Server Added to OS X Lion Server with 10.7.3 Update
Next: Secure Empty Trash in Mac OS X Lion

 

Shop for Apple & Mac Deals on Amazon.comspacer

Subscribe to OSXDaily

spacer spacer spacer spacer
Follow @OSXDaily

Shared on Facebook

Shop at Amazon

Ad

OSXDaily on Facebook

gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.