Reindex Spotlight from the Command Line in Mac OS X

Feb 2, 2012 - 9 Comments

Spotlight 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 of Mac OS X

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 Mac OS X

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, if a specific directory needs to be reindexed or was somehow left out of the spotlight search index.

.

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS, Tips & Tricks

9 Comments

» Comments RSS Feed

  1. CaptainClayCrash says:

    How long does the reindexing take? There seems to be no progress indicator?

  2. Nacho says:

    it ask me for the password!?!? i own this mac but never been ask for one?!?!

    any ideas!?

    • Frederic says:

      The account you are using is an administrative account but not the root account

      An easy way to enable the root account

      sudo passwd

      sudo will ask for a password. This is the password for the administrative account you’re currently using. Administrative accounts have super user rights so you can start programs that are otherwise restricted to the root account.

      With passwd you can set a password for the root user.

  3. Daniel says:

    When I run this for my external drive it says:

    Indexing disabled.

    How can I enable indexing on an external drive? Thanks.

    • Fake says:

      to enable indexing of a drive that you aren’t currently indexing:

      mdutil -i on “/Volumes/ExternalDrive”

      If you don’t know the correct name of the external drive, do this and look at the output:

      cd /Volumes
      ls

      (that’s L S in lowercase)

      If you want to see the indexing status of a particular drive, do this:

      mdutil -s “/Volumes/ExternalDrive”

      To ERASE THE SPOTLIGHT INDEX (NOT THE DRIVE ITSELF) and re-index a particular drive, do this:

      mdutil -E “/Volumes/ExternalDrive”

      To stop indexing an external drive, do this:

      mdutil -i off “/Volumes/ExternalDrive”

      Note that you must be an administrator on your computer. If you are not, precede each command with the word “sudo” which temporarily grants you administrative rights. You’ll need to type in the administrator’s password (which won’t display on the screen; but the administrator can read the log to know you’ve used his/her password, so be sure you have permission).

  4. Brad says:

    Alright so tried out this fix.

    Returned:
    No index.

    From there goes back to “home” command line.
    Any ideas?

  5. 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.

  6. 911 says:

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

    • Teddster says:

      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

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site