MacOS users can use Spotlight to help them find apps, documents, and other files on a Mac computer. Spotlight builds and maintains an index containing all this information which makes it easy to quickly find what you are looking for.
But did you know the Spotlight index is also used by mdfind, which is a command designed to be run from the terminal?
Check to see if the Spotlight index is enabled.
mdutil -s /
You should see
/: Indexing Enabled.
Or if you would like to be a bit more fancy.
echo Status of the macOS Spotlight indexer: $(sudo mdutil -s / | grep Index)
Status of the macOS Spotlight indexer: Indexing enabled.
Here is an example of using mdfind to search the entire hard drive for any .olm files that were created using Outlook.
sudo mdfind -name ".olm"
You can also search for and copy any .olm’s to a specific folder. This string takes into account any slashes (/), leading or trailing spaces within the file name.
sudo mdfind -name ".olm" | while IFS= read -r olms; do cp "$olms" /copy_files_here/; done
If you suspect that the Spotlight index is corrupt you can easily rebuild it. Here’s how to do it for all drives.
sudo mdutil -E /
*These commands were validated on macOS High Sierra 10.13.5