MacOSX和定位在iCloud驱动器上查找文件

我是一个Linuxpipe理员,我已经习惯了locate命令。 我不记得这个命令是否是OSX中的本地命令,或者如果我使用brew来安装它。

正如你可能知道定位是不同的发现,因为它创build一个数据库,允许从terminal快速search。 刷新数据库的常规Linux updatedb命令不适用于我,我必须使用: sudo /usr/libexec/locate.updatedb 。 另外configuration文件位于: /etc/locate.rc

我希望能够在iCloud Drive上find文件。 问题是,即使它设置为索引整个“/”系统,但找不到位于~/Library/Mobile Documents/com~apple~CloudDocs的iCloud Drive的索引。

我甚至将testing目的添加到configuration文件中,并运行列出的更新命令。 但是,找不到在iCloud驱动器上的文件。

我注意到,查找命令手册页,说:

 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. 

因此,也许我需要做一些技巧,并将用户添加到我的用户组,但是我从来没有听说过任何用户。 也没有usermod命令,如果我想追加我的普通用户组到nobody用户。

你们中的任何一个聪明的人都有build议来解决这个奇怪的要求吗?

我会跳过试图locate索引的文件,并使用macOS的类似,但更强大的系统,聚光灯。 与locate不同,它索引一切(但是将输出限制在用户可查阅的文件中)。 它也不断更新,索引远远多于文件名的文件属性。 它可以在命令行使用mdfind命令 。 默认情况下,它会search所有文件的索引属性, 如果您只想按名称search,请使用-name选项:

 $ 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 

请注意,它不使用与locate相同的查询语法; -name只是一个不区分大小写的名称 – 包含查找。 您可以使用Spotlight的元数据查询expression式语法获得更多的信息 :

 $ 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 

要更好地了解它可以search的属性,请使用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 = ( "public.plain-text", "public.item", "public.text", "public.data", "public.content", "public.plain-text" ) 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 = ( 501 ) kMDItemUserModifiedDate = ( "2017-09-01 19:06:52 +0000", "2017-09-01 19:07:06 +0000" ) kMDItemUserModifiedUserHandle = ( 501, 501 ) 

(虽然这实际上是不完整的 – 例如,它不包括文本文件的内容,这是完全索引和可search的。)