When Spotlight fails to find some files: mdutil revisited
Posted by jpluimers on 2025/11/07
On my M1 MacBook, somehow Spotlight started to fail returning some indexed files (especially recently added ones would not show up or it would take a very long while for some of them to show up).
So I revisited mdutil and related commands while writing a comment on the YouTube movie [Wayback/Archive] How To Rebuild the Spotlight Index on Your Mac – YouTube which since then vanished, but luckily I saved it and here I amended it with formatting:
My go to quick resource for terminal commands is ss64 is has cmd, PowerShell and *n*x derived ones all in one place.
For the Spotlight tool
mdutil, it has this page: https://ss64.com/mac/mdutil.htmlFirst step, check status (
-s) of all (-a) indexed volumes which combines into -sa to see which volumes have indexes turned on.
mdutil -saThen either turn off (-i off) then on (-i on) volumes that don’t return spotlight search results:
sudo mdutil -i off /Volumes/SanDisk400GB/
sudo mdutil -i on /Volumes/SanDisk400GB/If that fails, erase (-E) the index of that volume:
sudo mdutil -E /Volumes/SanDisk400GB/If that fails, erase (-E) all (-a) indices (indexes?) which combined forms -Ea
sudo mdutil -EaRegrettably, mdutil lacks a progress of the indexing process, so you have to resort to ⌘-space then search for a term to see that or revert to counting
mdworkerprocesses:
ps -ceo command | grep -c mdworkerIn the meantime, there are more mdutil options than the above page shows. In practice I have never used them, but this command shows them:
man mdutilA less repository of macOS man pages is at https://github.com/jpluimers/keith.xcode-man-pages with instructions how to export yourself.
Strange things can happen: in 2011 (post published in 2012) had one occasion where mysteriously all indexes had turned off.
https://wiert.wordpress.com/?p=6957
Last login: Mon Oct 31 19:31:01 on ttys000
macminiserver01:~ jeroenp$ mdutil -s /
/:
No index.
macminiserver01:~ jeroenp$ sudo mdutil -i on /
Password:
/:
Indexing enabled.
macminiserver01:~ jeroenp$
For volume names, I now used /Volumes/Macintosh HD and /Volumes/JeroensM1MBP1TB, but likely with newer disk/volume partitioning layout, I should have included /Volumes/Macintosh HD - Data as well. The first two solved my problem though, so I am happy.
The (for me not so big) drawback of using the command-line is that it requires sudo, so what you can also try in the MacOS Spotlight GUI is to exclude the affected volumes from Spotlight, then re-enable them. The place where you do this has changed over the various macOS versions (here mdutil is clearly at an advantage: rock solid user interface), so I include the most recent one:
- Click the in the top-left of the screen
- Choose “System Settings…”
- On the left, browse down to “Siri & Spotlight” (this is in the third group of icons, in that group the second one from the bottom):
(yup, macOS has tiny icons) - In the “Siri & Spotlight” pane on the right, browse to the bottom
- Click the “Spotlight Privacy…” button
- In the “Privacy” dialog, click the “+” button on the list
- In the Finder folder selection dialog, choose a folder that represents an affected volume, then click the “Choose” button on the bottom right of the dialog
- Back in the “Privacy” dialog, click the “Done” button on the bottom right of the dialog
- Back in the “Siri & Spotlight”, again click the “Spotlight Privacy…” button on the bottom right of the dialog
- Again in the “Privacy” dialog, select the volume you just added in the list, then click the “-” button, confirm you removed the volume and click the “Done” button on the bottom right of the “Privacy” dialog
- Close the Preferences dialog.
- On the keyboard press ⌘-space to open Spotlight
- Type a search term like “Index” then watch the indexing progress bar.
Sounds like a long list, right? That’s why I like mdutil, so:
Back to the terminal
All Spotlight related commands and other man pages:
- [Wayback/Archive]
mdfind(1) finds files matching a given query - [Wayback/Archive]
mdimport(1) import file hierarchies into the metadata datastore - [Wayback/Archive]
mdls(1) lists the metadata attributes for the specified file - [Wayback/Archive]
mdutil(1) manage the metadata stores used by Spotlight - [Wayback/Archive]
mddiagnose(8) gather information to aid in diagnosing Spotlight issues (on my system, this generates a folder in /tmp which totals to half a gigabyte, so I didn’t investigate this yet) - [Wayback/Archive]
mds(8) - [Wayback/Archive]
mdworker(8) metadata server worker (this does all the heavy lifting, so watch their resource usage: amount of processes, thread, memory, CPU usage, disk access) - [Wayback/Archive] grep(1) file pattern searcher
-c,--countOnly a count of selected lines is written to standard output.See below: needed to estimate on the terminal how busy the Spotlight indexer is.
- [Wayback/Archive] ps(1) process status
-A- Display information about other users’ processes, including those without controlling terminals.
-c- Change the “command” column output to just contain the executable name, rather than the full command line.
-e- Identical to
-A. -o- Display information associated with the space or comma separated list of keywords specified. Multiple keywords may also be given in the form of more than one
-ooption. Keywords may be appended with an equals (‘=’) sign and a string. This causes the printed header to use the specified string instead of the standard header. If all keywords have empty header texts, no header line is written.
Also needed to estimate on the terminal how busy the Spotlight indexer is, and since I never can remember single-character command-line switches this is much needed documentation.
All of these are from [Wayback/Archive] Xcode’s man pages which is the web-site generated by the below referenced GitHub repository by these scripts:
- [Wayback/Archive] xcode-man-pages/add_custom_css.py at main · keith/xcode-man-pages · GitHub
- [WaybackSave/Archive] xcode-man-pages/cleanup.sh at main · keith/xcode-man-pages · GitHub
- [Wayback/Archive] xcode-man-pages/export.sh at main · keith/xcode-man-pages · GitHub
- [Wayback/Archive] xcode-man-pages/generate-index.sh at main · keith/xcode-man-pages · GitHub
- [Wayback/Archive] xcode-man-pages/get-xcode-version.sh at main · keith/xcode-man-pages · GitHub
- [Wayback/Archive] xcode-man-pages/update.sh at main · keith/xcode-man-pages · GitHub
Links from the comment above:
- [Wayback/Archive] SS64 Command line reference
- [Wayback/Archive] mdutil Man Page – macOS – SS64.com
- [Wayback/Archive] GitHub – jpluimers/keith.xcode-man-pages: A HTML export of Xcode’s man pages
Then some pages that confirmed fingin Spotlight indexing progress from a Terminal is next to impossible despite mdworker doing the heavy lifting:
- [Wayback/Archive] How to tell if Spotlight is indexing. – Apple Community
You can also see in ActivityMonitor (in Utilities) if Spotlight is indexing:select CPU Tab button,then click the “ProcessName” column once to sort it alphabetically,find the mdworker name in the ProcessName column,as soon as the %CPU is above 0 it is “working” (even at 0% it is), it may be 50% or higher when indexing seriously… - [Wayback/Archive] How can I check if spotlight is still ind… – Apple Community
Open Activity Monitor and the CPU tap and see if the process mdworker is running with significant CPU %. mdworker does the indexing.
- [Wayback/Archive] macos – Is there a way to show Spotlight indexing status/progress in Yosemite? – Ask Different indicates there are no useful terminal commands to monitor Spotlight indexing progress.
- [Wayback/Archive] command line – Query Spotlight indexing status from Terminal – Ask Different confirmed that.
- [Wayback/Archive] How to tell if Spotlight is indexing on S… – Apple Community got me this surrogate solution:
If Spotlight is indexing, there will be a flurry of mdworker* processes running and you can determine that count with the following in the Terminal command line:ps -ceo command | grep -c mdworkerThis post was in fact the only one that gave me an idea how to get an idea on Spotlight indexing progress using just the Terminal.
Past blog-posts:
- After restoring fresh HDD from Time Machine Backup: No results from Spotlight
- Spotlight refuses to be enabled on Lion: reboot helped
- Mac OS X – Spotlight not finding many files: force a rescan solved it
- Redux: Mac OS X – Spotlight not finding many files: force a rescan solved it
- Spotlight taking 200% CPU
Siri icon: [Wayback/Archive] siri_1200x1200.jpg (1200×480)
Queries:
- [Wayback/Archive] spotlight fails to index downloads – Google Search
- [Wayback/Archive] mdutil man page – Google Search
- [Wayback/Archive] macos terminal view spotlight indexing progress – Google Search
--jeroen






Leave a comment