I'm a Linux admin and I'm used to the locate command. I don't remember if the command is native in OSX or if I installed it using brew.

As you may know locate is different from find, in that it creates a db, allowing for fast searches from Terminal. The regular Linux updatedb command that refreshes the db doesn't work for me, I have to use: sudo /usr/libexec/locate.updatedb. Also the configuration file is located at: /etc/locate.rc.

I want to be able to locate files on the iCloud Drive. Problem is even though it's set to index the entire "/" system, locate does not index the iCloud Drive, which is located at: ~/Library/Mobile Documents/com~apple~CloudDocs.

I even added that for test purposes to the configuration file and ran the listed update command. However locate never finds a file on the iCloud Drive.

I notice that the locate command man page, says:

The locate database is typically built by user ``nobody'' 
and the locate.updatedb(8) utility skips directories which are not
readable for user ``nobody'', group ``nobody'', or world.  
For example, if your HOME directory is not world-readable, 
none of your files are in the database.

So perhaps I need to do some trick and add the user nobody to my users group, however I have never heard of the nobody user before. Also there is no usermod command, if I wanted to append my normal users group to the nobody user.

Do any of you clever minds have a suggestion to solve this odd request?

  • Fixups for making migration to the SU easier. – peterh Aug 31 '17 at 13:59

I'd skip trying to get locate to index the files, and use macOS's similar-but-much-more-powerful system, Spotlight. Unlike locate, it indexes everything (but then limits output to files readable by the user doing the lookup). It also updates continuously, and indexes far more file attributes than just the filename. It's available at the command line with the mdfind command. By default, it searches all of the files' indexed attributes for whatever text you give it; if you want to search just by name, use the -name option:

$ mdfind -name icloud-file
/Users/gordon/Library/Mobile Documents/com~apple~CloudDocs/Example-iCloud-File-2.txt
/Users/gordon/Library/Mobile Documents/com~apple~CloudDocs/Example-iCloud-File.rtf

Note that it does not use the same query syntax as locate; -name just does a case-insensitive name-contains lookup. You can get much fancier using Spotlight's metadata query expression syntax:

$ mdfind "kMDItemFSName == iCloud-File"    # this does an exact-match search, so no matches
$ mdfind "kMDItemFSName == *iCloud-File*"    # Wildcards to the rescue!
/Users/gordon/Library/Mobile Documents/com~apple~CloudDocs/Example-iCloud-File-2.txt
/Users/gordon/Library/Mobile Documents/com~apple~CloudDocs/Example-iCloud-File.rtf
$ mdfind "kMDItemFSName == *iCloud-File* && kMDItemContentType == public.plain-text"
/Users/gordon/Library/Mobile Documents/com~apple~CloudDocs/Example-iCloud-File-2.txt

To get a better idea what attributes it can search for, use mdls:

$ mdls "/Users/gordon/Library/Mobile Documents/com~apple~CloudDocs/Example-iCloud-File-2.txt"
_kMDItemOwnerUserID            = 501
kMDItemContentCreationDate     = 2017-09-01 19:06:49 +0000
kMDItemContentModificationDate = 2017-09-01 19:07:06 +0000
kMDItemContentType             = "public.plain-text"
kMDItemContentTypeTree         = (
kMDItemDateAdded               = 2017-09-01 19:07:06 +0000
kMDItemDisplayName             = "Example-iCloud-File-2.txt"
kMDItemFSContentChangeDate     = 2017-09-01 19:07:06 +0000
kMDItemFSCreationDate          = 2017-09-01 19:06:49 +0000
kMDItemFSCreatorCode           = ""
kMDItemFSFinderFlags           = 0
kMDItemFSHasCustomIcon         = (null)
kMDItemFSInvisible             = 0
kMDItemFSIsExtensionHidden     = 0
kMDItemFSIsStationery          = (null)
kMDItemFSLabel                 = 0
kMDItemFSName                  = "Example-iCloud-File-2.txt"
kMDItemFSNodeCount             = (null)
kMDItemFSOwnerGroupID          = 20
kMDItemFSOwnerUserID           = 501
kMDItemFSSize                  = 22
kMDItemFSTypeCode              = ""
kMDItemKind                    = "Plain Text Document"
kMDItemLogicalSize             = 22
kMDItemPhysicalSize            = 4096
kMDItemUserCreatedDate         = (
    "2017-09-01 19:06:49 +0000"
kMDItemUserCreatedUserHandle   = (
kMDItemUserModifiedDate        = (
    "2017-09-01 19:06:52 +0000",
    "2017-09-01 19:07:06 +0000"
kMDItemUserModifiedUserHandle  = (

(Although this is actually incomplete -- for example, it doesn't include the text file's contents, which is fully indexed and searchable.)

  • Thank you Gordon. Mdfind does exactly what I'm missing from locate. Thanks again! – Raker Sep 3 '17 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.