Subscribe to OSXDaily

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

Shared on Facebook

Shop at Amazon

Ad

OSXDaily on Facebook

Search spotlight

Reindex Spotlight from the Command Line

Feb 2, 2012 - 3 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

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.

Stop Spotlight from Indexing Time Machine Backup Volumes & External Drives

Jan 24, 2012 - 2 Comments

Stop Spotlight from Indexing Time Machine Drives

The default behavior for Spotlight is to start indexing any drive as soon as it’s connected to a Mac, a task that can take a very long time with larger volumes. The problem is that for larger external backup drives and Time Machine volumes, you don’t necessarily want it indexed by Spotlight. This is particularly true if the drive gets used on multiple machines, where indexing on each Mac isn’t necessary.

The solution is simple enough, the same method used to exclude something from Spotlight can also be used to stop Spotlight from indexing a Time Machine drive or other external volume:

  1. Connect the volume you want excluded to the Mac, even if Spotlight is currently indexing
  2. Launch “System Preferences” and click on “Spotlight” followed by the ‘Privacy’ tab
  3. Drag the drives icon into the Privacy window

Even if the drive is currently being indexed by Spotlight, this will cease the indexing process and prevent the drive from being reindexed again on that Mac. You’ll have to redo this process on each Mac that the drive is connected to.

If a drive is removed from the privacy list, it will automatically start a rebuild of the Spotlight index for that volume, however.

Stopping Spotlight from Indexing Backups & External Drives from the Command Line

If you’d rather prevent a drive from being indexed from the command line, you can do that with mdutil and the following syntax:

mdutil -i off /Volumes/VolumeName

When the command has executed properly, you’ll see something like this:

$ mdutil -i off /Volumes/MediaCenterMovies
/Volumes/MediaCenterMovies:
Indexing and searching disabled.

Be sure to specify a full volume path, because if you just use / or don’t use proper syntax you could wind up disabling Spotlight systemwide.

Reversing this and reenabling indexing on a per volume basis is just a matter of changing the flag from off to on:

mdutil -i on /Volumes/VolumeName

Again you’ll get a message, this time confirming the path and “Indexing enabled.”

Rebuild the Spotlight Index

Jan 17, 2012 - 4 Comments

Rebuild the Spotlight Index

Do you need to rebuild the entire Spotlight index on a Mac? It’s easy to do, but can take a while. Here’s how to start the reindexing process of an entire drive using the Spotlight control panel:
Read more »

How to Exclude Hard Drives and Folders from Spotlight Index in Mac OS X

Dec 30, 2011 - 7 Comments

Exclude drives and folders from Spotlight index

Spotlight is a wonderful feature of Mac OS X, but sometimes you don’t want it indexing everything. Whether it’s an external backup drive, a scratch disk, or just a private folder with files you don’t want easily found, excluding drives and directories from Spotlight is easy:

  • Launch System Preferences from the  Apple menu and click on “Spotlight”
  • Click on the “Privacy” tab
  • Drag & drop folders or drives to exclude from the Spotlight index, or click the “+” plus icon in the corner to manually select hard drives or directories

Anything folder or drive in that list is effectively hidden from the Spotlight index, making the contents not appear in file searches.

Exclude items from Spotlight index

This is a much better approach than disabling Spotlight if all you want to do is hide certain files from prying eyes.

If at any point you want these items to be reindexed and reincluded within Spotlights search results, all you need to do is highlight them in the privacy tab and delete them with the Delete key or by hitting the “-” minus button in the lower left. Removing items will trigger the mds and mdworker processes to run.

On a side note, because excluding items and then reincluding them also causes that directory or drive to be completely reindexed, this can be a helpful troubleshooting tip if you’re running into location specific problems with Spotlight.

Hide the Spotlight Menu Icon in Mac OS X Lion

Dec 12, 2011 - 13 Comments

Hide the Spotlight icon in OS X Lion

Whether you are disabling Spotlight or just wanting to reduce menubar icon clutter, it’s possible to hide the Spotlight icon. Here’s the best part though; if you just want to hide the Spotlight menu, you can do so without disabling the search abilities from functioning in the Finder or with other apps that rely on the Spotlight metadata.

Hide the Spotlight Menu Icon in OS X Lion

This does not disable Spotlight or mds, it only hides the icon from the menubar.

Launch the Terminal from /Applications/Utilities/ and type the following:

sudo chmod 600 /System/Library/CoreServices/Search.bundle/Contents/MacOS/Search

Next, you kill a process called SystemUIServer to refresh the menubar and have the change take effect:

killall SystemUIServer

What you’ll find is the Spotlight menu is removed, but the search abilities built into Finder still work as seen in the screenshot showing the “Searching This Mac” window, accessible with Command+F :

Hiding the Spotlight menu still allows search to work

Show the Spotlight Menu Again

Getting the Spotlight icon back is a matter of bringing the permissions back to their default setting:

sudo chmod 755 /System/Library/CoreServices/Search.bundle/Contents/MacOS/Search

Follow this up with killing the SystemUIServer again:

killall SystemUIServer

The Spotlight menu will be visible again:

Show the Spotlight icon again

Thanks to Juan for the tip via comments.

How to Disable (or Enable) Spotlight in Mac OS X Lion

Dec 10, 2011 - 23 Comments

Disable Spotlight in OS X Lion

Completely disabling and reenabling Spotlight in Mac OS X Lion can be done with the help of the Terminal. The following command unloads the Spotlight mds agent from launchd, preventing the daemon from running or indexing any drives entirely.

Open up the Terminal (found in /Applications/Utilities/) and enter the following commands based on the need to either disable or reenable Spotlight indexing. This will effect indexing on all drives connected to the Mac.

Disable Spotlight

The primary method is using launchctl, this will require the administrative password:
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

Another approach is to use the older indexing method of “sudo mdutil -a -i off” which turns off indexing only, but more on that in a minute.

Reenable Spotlight

The guaranteed way to reenable Spotlight is to reload it into launchd using launchctl:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

Again, the alternate approach is the indexing related “sudo mdutil -a -i on” command, but that method can throw the “Spotlight server is disabled” error and not allow you to turn it back on. If you run into that problem, use the sudo launchctl load command instead to enable both indexing and Spotlight.

With Spotlight reloaded launchd, the mds agent will immediately start running again to reindex the filesystem. Depending on the amount of changes and new files since the last time MDS ran, this can take a while. You can verify that MDS is running through Activity Monitor or by pulling down the Spotlight menu to see an “Indexing Drive Name” progress bar.

Enable Spotlight in OS X Lion

Did Apple Inspire Google? Google Instant is Spotlight for the Web

Sep 13, 2010 - 13 Comments

google-instant

There’s a lot of hooplah in the web world about Google Instant and it’s ability to turn up search results immediately while you type them. Is Google Instant really as new and revolutionary as it’s claimed to be? Yes and no. Yes for the web, and no for computing. You know what other prominent search engine has been providing instant and predictive search results based on user input? Apple’s very own Spotlight.
Read more »

mds – what MDS process is and why it uses CPU on the Mac

Aug 5, 2010 - 11 Comments

mds mac
If your Mac is suddenly running sluggish and you launched Activity Monitor, you may notice a process named ‘mds’ cranking away at 30% and even up to 90% CPU utilization. If you see this, don’t worry, it’s not abnormal behavior and your Mac isn’t crashing, it’s just indexing it’s built in search engine.

What is MDS in Mac OS?

mds stands for “metadata server” and the mds process is part of Spotlight, the amazingly powerful and very useful search feature built directly into the foundation of Mac OS X. You access Spotlight by hitting Command+Spacebar.

An easy way to identify that mds and Spotlight is indexing is to look at the Spotlight icon in the upper right corner of your menubar, when Spotlight is indexing the magnifying glass will have a dot in the center like so:

mds update

You can then click on the Spotlight icon and you’ll see your main hard drive being indexed, with a progress bar and estimated time until completion:

mds updating

Is the mds process related to mdworker?

Yes. Usually you will see the mds process in conjunction with mdworker, which is another part of Spotlight and it’s indexing engine.

How long does mds & Spotlight take to finish indexing?

How long it takes to update the Spotlight index depends on a few variables, but mostly the size of your hard drive, the amount of data being indexed, major changes to the filesystem, and the time since last indexing. Just let the indexing complete, it generally takes between 15 and 45 minutes to complete.

If Spotlight isn’t working, you can check out these Spotlight troubleshooting tips which will get you situated again. If you don’t ever use the search feature or just don’t like it, you can also disable Spotlight and all of its indexing.

Search JPEG only within Spotlight

Jul 30, 2010 - 1 Comment

search jpeg spotlight
Do you know you’re looking for a JPEG but don’t want to search every other document type on your Mac? Speed up your search thanks to Spotlight search operators, just type:
kind:jpeg filename With this the only documents searched will be jpeg. You can specify just about any kind of document, from pdf, to doc, txt, etc.

There’s a whole post on search operators within Spotlight if you’re interested.

Turn Spotlight into an application launcher only

Jul 6, 2010 - 3 Comments

You can easily turn Spotlight into only an application launcher by adjusting the Spotlight search settings.

* Launch System Preferences
* Click the Spotlight icon
* Uncheck every item except for “Applications” and “System Preferences”
* Close System Preferences

Now your Spotlight menu will only return Application and System Preference results when a search is made, making for a very quick and completely integrated application launcher. Of course, you can use Spotlight as an application launcher even with the other search category items selected, but your search results will be a bit more cluttered.

spotlight application launcher