mdfind does not seem to find files in /opt.


$ mdfind -onlyin /opt -name Dockerfile

find produces the expected result

$ find /opt -name Dockerfile

Why might /opt be invisible to mdfind? Is there some system setting that will get mdfind to work?


On my system, /opt is just a regular directory. It is not a mount point or a symlink or anything special.

$ ls -ld /opt
drwxr-xr-x  4 root  wheel  128 Jan  3  2022 /opt

$ df -kh /opt
Filesystem     Size   Used  Avail Capacity iused      ifree %iused  Mounted on
/dev/disk3s5  460Gi  359Gi   75Gi    83% 3302051 4824674469    0%   /System/Volumes/Data

$ mdls /opt
kMDItemFSContentChangeDate = 2022-01-03 20:30:37 +0000
kMDItemFSCreationDate      = 2021-01-25 11:56:41 +0000
kMDItemFSCreatorCode       = ""
kMDItemFSFinderFlags       = 0
kMDItemFSHasCustomIcon     = 0
kMDItemFSInvisible         = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSIsStationery      = 0
kMDItemFSLabel             = 0
kMDItemFSName              = "opt"
kMDItemFSNodeCount         = 2
kMDItemFSOwnerGroupID      = 0
kMDItemFSOwnerUserID       = 0
kMDItemFSSize              = 2
kMDItemFSTypeCode          = ""
  • 3
    find is a real-time search of the filesystem. mdfind uses the Spotlight database. Spotlight does not index every directory. Dec 26, 2021 at 20:04
  • @MarcWilson How does Spotlight decide what directories to index? If possible, I'd very much like to get /opt into the Spotlight database.
    – sigjuice
    Dec 26, 2021 at 20:20
  • 2
    Just to confirm. mdfind fails to return any items with either search by name or search by content. But Finder search does return items for search by name (not by content) - that seems odd to me.
    – Gilby
    Dec 29, 2021 at 2:51
  • mdfind works for me in /opt. Is your opt just a directory, or does it point to a mount somewhere else? Jul 18, 2022 at 18:41
  • @SpinUp /opt is just a regular directory on my system. I have added details to my original question. Thanks!
    – sigjuice
    Jul 19, 2022 at 19:49

1 Answer 1


mdimport /opt

will perform a one-time import. I believe that you will have to periodically re-run this command to keep the index updated.

  • This doesn't seem to work. I tried mdimport /opt and tried my original mdfind command, but got no output.
    – sigjuice
    Dec 29, 2021 at 0:05
  • 1
    @sigjuice Doesn't work for me either. Confirmed further by the output of mdls /opt/<file> which return minimal metadata. Duplicate one of the files to /usr and there is expected metadata and mdfind works as expected with results for both search by name and search by content.
    – Gilby
    Dec 29, 2021 at 3:01
  • Could it be a permissions problem? Try the mdimport command with sudo? Or turn on debugging output like mdimport -t -d2 /opt? Jul 18, 2022 at 18:44
  • Another idea: the GUI version of this is to exclude the directory in spotlight's system preference pane, then remove it from the exclusion list. That should trigger a re-index. Jul 18, 2022 at 18:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .