复合mdfind搜索 [英] Compound mdfind search

查看:72
本文介绍了复合mdfind搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标是查找特定州或国家/地区中的所有图像.

The goal is to find all images that are in a certain state or country.

mdfind kind:image

将找到所有图像

mdfind "kMDItemCountry == 'United States'"

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

will find all files what have this property.

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

失败.我尝试使用&&和()的各种分组,但无法使其正常工作.如何将'kind:image'与属性搜索(如kMDIxxx)成功结合?

fails. I've tried using && and various groupings of () but can't make it work. How can I successfully combine 'kind:image' with attribute searches like kMDIxxx?

推荐答案

我有机会对 mdfind 的实际工作方式进行了一些实验,这与文件的记载方式相反-两者不同.

I have had a chance to do some experiments as to how mdfind really works, as opposed to how it is documented - the two differ.

首先,让我们看一下Mac上挂着的名为 tardis.png 的文件的Spotlight数据.

First, let's look at the Spotlight data for a file called tardis.png that was hanging around on my 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

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

And here is a query that matches and lists that file:

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

这说明了如何使用&& (AND)和 || (OR)进行复合搜索,以及如何将括号内的条件分组(conditionA|| conditionB),以及如何进行不区分大小写的搜索(通过在搜索字符串后附加 c ).

That shows how to do compound searches with && (AND) and || (OR), how to group conditions within parentheses (conditionA || conditionB) and also how to do case-insensitive search (by appending c after the search string).

示例:也许更多供我参考;-)

Examples: maybe more for my own reference ;-)

列出我用来在Mac上拍照的所有相机和扫描仪:

List all cameras and scanners that I have used to make pictures on my 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上拍摄的所有照片:

Find all photos shot on iPhone 6:

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


注释:

  • 手册页上说 -onlyin 将搜索范围限制为指定的目录.这确实是不正确的,因为它也会递归到包含的目录中.

  • The man-page says -onlyin limits the scope of the search to the specified directory. That is not really correct, because it recurses into contained directories too.

在比较中使用单( = )还是双( == )等号似乎没什么区别.

It seems to make no difference whether you use single (=) or double (==) equals signs in comparisons.

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

The documentation says you can use string==[c]"pattern" for case-insensitive search, that is incorrect and the syntax I have shown above does work on macOS Sierra at least.

这篇关于复合mdfind搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆