复合mdfind搜索

时间:2017-08-26 20:29:03

标签: macos macos-sierra

目标是查找处于特定州或国家/地区的所有图像。

mdfind kind:image

会找到所有图片

mdfind "kMDItemCountry == 'United States'"

将找到具有此属性的所有文件。

mdfind kind:image "kMDItemCountry == 'United States'" 

失败。我试过用&&和()的各种分组但不能使它工作。如何成功将'kind:image'与kMDIxxx等属性搜索结合起来?

1 个答案:

答案 0 :(得分:1)

我有机会对mdfind如何真正起作用做一些实验,而不是如何记录 - 两者不同。

首先,让我们看一下名为tardis.png的文件的Spotlight数据,该文件在我的Mac上闲逛。

mdls tardis.png

<强>输出

_kMDItemOwnerUserID            = 501
kMDItemBitsPerSample           = 32
kMDItemColorSpace              = "RGB"
kMDItemContentCreationDate     = 2017-05-31 14:15:03 +0000
kMDItemContentModificationDate = 2017-05-31 14:15:03 +0000
kMDItemContentType             = "public.png"
kMDItemContentTypeTree         = (
    "public.png",
    "public.item",
    "public.png",
    "public.data",
    "public.image",
    "public.content"
)
kMDItemCreator                 = "Adobe Photoshop CC 2017 (Macintosh)"
kMDItemDateAdded               = 2017-05-31 14:15:23 +0000
kMDItemDisplayName             = "tardis.png"
kMDItemFSContentChangeDate     = 2017-05-31 14:15:23 +0000
kMDItemFSCreationDate          = 2017-05-31 14:15:22 +0000
kMDItemFSCreatorCode           = "8BIM"
kMDItemFSFinderFlags           = 0
kMDItemFSHasCustomIcon         = (null)
kMDItemFSInvisible             = 0
kMDItemFSIsExtensionHidden     = 0
kMDItemFSIsStationery          = (null)
kMDItemFSLabel                 = 0
kMDItemFSName                  = "tardis.png"
kMDItemFSNodeCount             = (null)
kMDItemFSOwnerGroupID          = 20
kMDItemFSOwnerUserID           = 501
kMDItemFSSize                  = 1488497
kMDItemFSTypeCode              = "PNGf"
kMDItemHasAlphaChannel         = 0
kMDItemKind                    = "Portable Network Graphics image"
kMDItemLogicalSize             = 1488497
kMDItemOrientation             = 1
kMDItemPhysicalSize            = 1490944
kMDItemPixelCount              = 2091600
kMDItemPixelHeight             = 1494
kMDItemPixelWidth              = 1400
kMDItemProfileName             = "sRGB IEC61966-2.1"
kMDItemResolutionHeightDPI     = 72
kMDItemResolutionWidthDPI      = 72

这是一个匹配并列出该文件的查询:

mdfind -onlyin . "(kMDItemPixelHeight>1500 || kMDItemPixelWidth=1400)&& kMDItemKind='*image*' && kMDItemProfileName='srgb*'c"

显示了如何使用&&(AND)和||(OR)进行复合搜索,如何对括号(conditionA || conditionB)中的条件进行分组以及如何进行不区分大小写的搜索(在搜索字符串后添加c

示例:可能更多供我自己参考; - )

列出我用于在Mac上制作图片的所有相机和扫描仪:

mdfind -0 kind:image |  xargs -0 mdls -n kMDItemAcquisitionModel | sort -u
kMDItemAcquisitionModel = "645 PRO Mk III for iOS"
kMDItemAcquisitionModel = "BlackBerry 8900"
kMDItemAcquisitionModel = "BlackBerry 9000"
kMDItemAcquisitionModel = "Canon EOS 5D Mark III"
kMDItemAcquisitionModel = "Canon EOS 5D"
kMDItemAcquisitionModel = "Canon EOS 7D Mark II"
kMDItemAcquisitionModel = "Canon EOS 7D"
kMDItemAcquisitionModel = "Canon EOS-1D Mark II N"
kMDItemAcquisitionModel = "Canon EOS-1D Mark IV"
kMDItemAcquisitionModel = "Canon EOS-1D X"
kMDItemAcquisitionModel = "Canon EOS-1DS"
kMDItemAcquisitionModel = "Canon EOS-1Ds Mark II"
kMDItemAcquisitionModel = "Canon EOS-1Ds Mark III"
kMDItemAcquisitionModel = "EOS-1Ds Mark III"
kMDItemAcquisitionModel = "EPSON Perfection 4990"
kMDItemAcquisitionModel = "NIKON D800"
kMDItemAcquisitionModel = "NIKON D800E"
kMDItemAcquisitionModel = "Perfection 4990"
kMDItemAcquisitionModel = "Perfection4990"
kMDItemAcquisitionModel = "PerfectionV700  "
kMDItemAcquisitionModel = "PerfectionV700"
kMDItemAcquisitionModel = "TANGO           "
kMDItemAcquisitionModel = "TANGO"
kMDItemAcquisitionModel = "iPad mini 4"
kMDItemAcquisitionModel = "iPad mini"
kMDItemAcquisitionModel = "iPad"
kMDItemAcquisitionModel = "iPhone 3G"
kMDItemAcquisitionModel = "iPhone 3GS"
kMDItemAcquisitionModel = "iPhone 4"
kMDItemAcquisitionModel = "iPhone 4S"
kMDItemAcquisitionModel = "iPhone 5"
kMDItemAcquisitionModel = "iPhone 5s"
kMDItemAcquisitionModel = "iPhone 6"
kMDItemAcquisitionModel = "iPhone 6s"
kMDItemAcquisitionModel = "iPhone SE"
kMDItemAcquisitionModel = "iPhone"

查找在iPhone 6上拍摄的所有照片:

mdfind "kMDItemAcquisitionModel='*iPhone*6*'"

备注

  • man-page说-onlyin将搜索范围限制在指定目录中。这不是真的正确,因为它也会递归到包含的目录中。

  • 在比较中使用单个(=)或双(==)等于符号似乎没有区别。

  • 文档说您可以使用string==[c]"pattern"进行不区分大小写的搜索,这是不正确的,我上面显示的语法至少可以在macOS Sierra上使用。