How many of you remember Sherlock? Until the early years of macOS X, Apple’s old charismatic search engine used to bring up everything we searched for on the internet and on our computers. Then, as you know, it was replaced by the metadata-based Spotlight. As old Mac users, we may love Sherlock, but it didn’t take us long to forget him once we saw the capabilities of Spotlight.

First, the basics
If you’re reading this article, I assume you know what Spotlight is, but if you don’t, let me summarize in a sentence or two. Spotlight is the name of macOS’ built-in search engine. It’s a metadata-driven search engine, so it can scan every piece of data about all the files you have on your computer. For example, if a document named New_file.pdf contains an address located in Hamburg-Germany, you can access that document by searching for the keyword “Hamburg”. Or you can search for the keyword “1600” to find image documents that are, for example, 1600px wide. Or you can do silly searches like; “Find documents on my computer that are larger than 500MB and created in the last 6 months”
If you look at Spotlight’s settings in the System Settings window, you can see that there are settings to restrict Spotlight. You can set restrictions based on file type. For example, “PDF documents should not be shown in search results”. Or you can restrict by folder by clicking on the Privacy tab. For example, “<My Work> folder should not be included in search results”.
In summary, like many system features in macOS, Spotlight has very few end-user configurable features.
Let’s dig a little deeper
In order for Spotlight to see the contents of your computer as searchable items, it needs to index the contents of your entire computer. Just like Google indexes every single website.
If you’ve bulk-loaded your old data onto a new Mac you bought, Spotlight will index individual files in that dataset. Or if you’ve updated macOS on your current computer, Spotlight will start with indexing. During indexing, your computer may slow down significantly and you may not get the results you want from your searches.
The indexed data is stored in the main directory of your disk (usually called Macintosh HD) in a hidden document called .Spotlight-V100. You can see this index file if you first issue the cd / command from the terminal and then navigate to the /private/var/db/ directory.
cd /
cd private/var/db/
The Spotlight index is managed by a daemon called Meta Data Server, which is handled by a task called mdworker. When you check with Activity Monitor, you can see tasks named mds or mdworker. As I mentioned above, you may notice that the computer slows down during indexing. In such a case, you can see in Activity Monitor that tasks named mds or mdworker are consuming extra CPU power and memory.
As you know, you can force quit (⌘+⌥+Esc) open applications in Finder. In addition, you can also terminate tasks executed by the operating system using Activity Monitor. And yes, you can also terminate mds and mdworkervia Activity Monitor. If you do this, Spotlight will not index your files.
What you can do through the terminal
You can also use various Spotlight-oriented commands from the terminal. Let me try to illustrate a few of them.
First of all, you can do your searches through Terminal. For this you need to use the mdfind command. For example, if you type “mdfind flower /” you will search for the word flower in your home directory (i.e. the whole computer).
mdfind flower /
If you do not want to search the entire disk, but only a specific folder, you should use onlyin. If you type “mdfind flower -onlyin ~/Documents” it will only search for the word flower in the Documents folder.
There is a toolkit for using Spotlight that you can access from Terminal. You can access the options of this toolkit with the mdutil command. For example, with the command “mdutil -s” you can find out whether the indexing feature of any disk is on or off. If you want to get this information for your main directory, you should type “mdutil -s /”. Or if you want to get this information for an external disk named ‘Backup’, type “mdutil -s /Volumes/Backup”.
You can turn indexing on and off for your disks using the mdutil commands. To turn indexing on, type “sudo mdutil -a -i on”. The -a option here applies this operation to all disks (external and internal) connected to your computer. Similarly, typing “sudo mdutil -a -i off” will turn off indexing on all disks.
If you want to delete all your Spotlight index files that have been created so far and re-create them, just type “sudo mdutil -a -E”.
sudo mdutil -a -E
For all other commands that can be used with the mdutil command, see the mdutil manual page in Terminal. You can access the manual page by typing “man mdutil”.

Leave a Reply