How To Easily Search For Files Using AND, OR and NOT

When you search for files you can use boolean operators like AND, OR and NOT. The hard way is to use the convoluted search interface. But you can also just type out your search request to get it done quickly and simply.

Comments: 13 Responses to “How To Easily Search For Files Using AND, OR and NOT”

    Neil
    1 year ago

    Good tip.

    This doesn’t seem to work in the search field in Photos.

    Searching for two or more “Family_Bob Family_Sue” keywords uses ‘and’ operation. Doesn’t seem to be an ‘or’ operation available to get two groups of photos combined.

    Smart albums are clumsy if you just want something temporary.

    Is there a better way?

    1 year ago

    Neil: This video is for searching in the Finder, not in Photos. Using a Smart Album would be the way to go in Photos.

    Chris in CT
    1 year ago

    Very helpful!
    Where would one find a list/dictionary of search terms beyond Name, Kind, Created, etc.?

    1 year ago

    Chris: I don't know of any comprehensive list, but Apple shows some here: https://support.apple.com/guide/mac-help/narrow-search-results-mh15155/mac
    You can also sometimes get more by creating a Smart Folder, then opening that Smart Folder's file in a text editor to examine how the search terms are represented in the text.

    Jasper
    1 year ago

    Hi Gary,
    1. When I open a SavedSearch, I get a long xml file, which includes, e.g., 'kMDItemUserTags = "Flock 🐑"cd) Query. What would one do with this? It's not the same format as the Finder search tokens...although pasting it in retrieves the SavedSearch file.

    2. And I'm I right in thinking that there's no Finder token to restrict the search to a specific file? Something like 'folder:Documents'

    TIA, Jasper

    1 year ago

    You use it in the same way you use the tokens in my examples. So instead of name:myname you would use kMDItemUserTags:mytag. It is just the "kMDItemUserTags" you are looking for.
    You don't include the folder (path) in the search part, you do that by starting in that folder. See at the top in my example it shows "This Mac" and "Documents" and Documents is chosen because that is where I was when I started the search.

    Bernard
    1 year ago

    When I type the search string “name:test” into the search field the system internally uses the matches option. How can I change it to the contains option?
    In the “savedSearch” XMLs it looks the following:
    1) matches: “(kMDItemDisplayName = "test*"cdw)"
    2) contains: “(kMDItemDisplayName = "*test*”cd)”
    Both options “kMDItemDisplayName:test*" or “...Name:*test*” don’t work in the Finder search field. Only without asterisks I get results but then I won't find compound words like “retest”.

    1 year ago

    Use command+option+f and then the fields and menus below to do complex searches like that instead

    Bernard
    1 year ago

    Sure, but that's very cumbersome to select the same items from two drop-down lists over and over again when I principally want to use the contains option. I wonder why the option in the standard search dialog was renamed to “Name Contains” while “matches” is still used in the background? In older OS X versions the option was correctly called “Name matches”.
    https://discussions.apple.com/content/attachment/c5f27137-a5d9-4f2d-947b-db07a6de2ea6

    Terry
    1 year ago

    When I search in finder I will only get results if I select my This Mac. If I try to search within any of the folders I get 0 results. The file does exist in the searched folder and will only be found if I choose This Mac. A full Spotlight search will also find the file.

    1 year ago

    Terry: Not sure why that would be the case. Maybe work with Apple Support to figure out what could be going on.

    Rick
    1 year ago

    I want to exclude a particular file type from seeing it in my "Godot projects" directory and its subdirectories. I can simply type "NOT:import" in the filter field. However, I want to keep this filter turned on as long as I'm working and regardless of in which directory I'm in. But as soon as I enter into any subdirectory of the "project" folder, the search bar is reset. Is there a way to keep it fixed? And Saved Search saves the results for the current folder only, so that's not much help eithe

    1 year ago

    Rick: No, you have to tell it each time that you ant it excluded.

Comments Closed.