Mac search for file extension, done accurately

To search for a file extension on a Mac, open a Finder window, press Command-F, click the plus button under the search field, set the rule to Name, ends with, and type the extension with its dot, for example .pdf. That returns every indexed file whose name really ends in .pdf, which is what most people mean. Typing .pdf straight into the search field also works, but it matches more loosely, and the Terminal tools mdfind and find each give a different answer again. This article shows all of them, with the exact menu names, and explains a measurement where three methods returned three different counts for the same folder.

The quick answers, side by side

Each method searches something slightly different. Picking the right one is mostly about what you need to be sure of.

Method Where What it matches Misses
Name ends with .pdf Finder search rule row Names ending in .pdf, any case Files Spotlight has not indexed
kind:pdf Finder or Spotlight search field Files whose type is PDF, whatever the name File types that have no kind: keyword
Typing .pdf alone Finder search field Names containing .pdf anywhere, plus some content matches Precision
mdfind Terminal Whatever query you write against the Spotlight index Files Spotlight has not indexed
find -iname Terminal Every file on disk under a folder, by name Nothing, but it is slower on large folders

The first four all read the Spotlight index. Only find walks the disk itself. That single difference explains most of the surprises people run into, and the measurement further down shows how large it can be.

Searching by extension in Finder, step by step

Apple's page on how to narrow your search results in Finder (checked October 9, 2026) describes the rule rows. Applied to extensions, the steps are:

  1. Open the folder you want to search, then press Command-F.
  2. Under the search field, make sure the scope shows the folder's name, not "This Mac", unless you want the whole disk.
  3. Click the plus button at the right of the search bar. A rule row appears.
  4. In the first pop-up menu, choose Name. In the second, choose ends with.
  5. Type the extension with its dot, such as .pdf, .md or .heic.

The results update as you type. Matching is not case sensitive, so .pdf also finds REPORT.PDF.

To search for several extensions at once, hold Option and the plus button turns into an ellipsis. Clicking it adds a group where you can choose Any of the following are true, then add one Name ends with row per extension. That gives you, for example, every .jpg, .jpeg and .heic file in one list.

Typing the extension straight into the search field

Typing .pdf into the search field without a rule row does work, but Finder offers suggestions in a menu under the field. Choosing the one under Filenames limits the match to names. Pressing Return without choosing searches names and file contents together, so documents that mention ".pdf" in their text appear as well. That is the most common reason a quick search returns too many results.

Choosing the scope before you search

The scope row under the search field decides how many results come back, and it resets on every new search. Searching "This Mac" for .json on a developer's machine can return tens of thousands of files, most of them inside tool and dependency folders. Starting the search from the folder that matters, and checking that its name is selected in the scope row, keeps the list readable.

The default can be changed. In Finder > Settings > Advanced, the menu "When performing a search" offers Search This Mac, Search the Current Folder and Use the Previous Search Scope. Setting it to the current folder means Command-F always starts where you are, which suits extension searches well because the folder is usually the real question.

Searching by type instead of name

When you care about what a file is, not what it is called, use the Kind criterion instead of Name. The Kind menu includes PDF, Image, Movie, Music, Presentation, Text and more, and Other lets you type a kind that is not in the list. In the search field, the same thing is written as kind:pdf or kind:images. Apple's page lists the keywords it understands, including kind:pdf, kind:movie and kind:presentation.

Kind and extension usually agree, but not always. A PDF saved without an extension is still a PDF to Spotlight, because macOS records a file's type separately. Apple calls these types Uniform Type Identifiers; a PDF's identifier is com.adobe.pdf.

Saving the search so it stays up to date

A search you will repeat is worth saving. After building the rule rows, click Save under the search field, give it a name, and leave Add To Sidebar ticked. Finder creates a Smart Folder: a saved search that updates itself as matching files are added, renamed or deleted. Apple's guide to creating or changing a Smart Folder covers it in full. Option-Command-N creates a new Smart Folder directly from the keyboard.

Smart Folders are useful for extensions in a few specific ways:

  • "All .psd files changed in the last 30 days", by adding a Last modified date rule to the Name row.
  • "Every .key and .pptx file", using an Any group, as a single list of presentations regardless of the app that made them.
  • "Every .log file over 100 MB", by adding a File size rule, to find what is filling the disk.

To change a saved search later, open the Smart Folder, click the Action menu (the circle with three dots) and choose Show Search Criteria.

A Smart Folder is still a Spotlight search. It inherits the same blind spots as every other index-based method, which the next section measures.

Why three methods gave three different counts

To see how far the methods can drift apart, the editorial desk ran three searches for PDF files against one ordinary Downloads folder on a Mac running macOS 27.0.1, on October 9, 2026. The folder held a typical mix: downloaded documents, scanned papers, and a couple of installer folders.

Command Results
mdfind -onlyin ~/Downloads "kMDItemFSName == '*.pdf'c" 341
mdfind -onlyin ~/Downloads -name .pdf 356
find ~/Downloads -iname '*.pdf' 387

The first command is the Terminal equivalent of Name ends with .pdf: it compares the file name against a pattern, and the trailing c makes the comparison case insensitive. It returned 341.

The second, mdfind -name .pdf, returned 15 more. Comparing the two lists showed why: -name matches names that contain .pdf anywhere. The extra results were image and interface files whose names had .pdf in the middle, followed by another extension. They are not PDFs.

The third, find, returned 46 more than the first. Almost all of the extra files sat inside application bundles (folders ending in .app, which macOS shows as a single file) and inside an uninstaller's folder. Spotlight does not index the inside of app bundles by default, so no Finder search or mdfind query will ever show them. A handful of the remaining extras were recent downloads the index had not picked up yet.

The lesson is narrow but practical. If a missing file would cost you something, check with find. If you want a fast, filterable list of the documents you work with, Finder's rule rows are the better tool, and the gap is mostly files you would not want in the list anyway.

Terminal commands for exact control

Two commands cover nearly every extension search from Terminal.

mdfind: fast, uses the index

mdfind queries the same Spotlight index Finder uses, so it returns in well under a second even across a whole disk.

mdfind -onlyin ~/Documents "kMDItemFSName == '*.md'c"
mdfind -onlyin ~/Documents -count "kMDItemFSName == '*.md'c"
mdfind "kMDItemContentType == 'com.adobe.pdf'"

The first lists every Markdown file under Documents. The second prints only the count, which is useful before deciding whether to act on the results. The third searches by type rather than name, matching every PDF regardless of what it is called. Running mdls on a file shows its type and every other attribute Spotlight stores:

mdls -name kMDItemContentType report.pdf

find: slower, reads the disk

find does not use the index. It walks every folder under the starting point, so it is slower on large trees but sees everything, including the inside of app bundles and folders Spotlight is told to skip.

find ~/Projects -iname '*.json'
find ~/Projects -iname '*.json' -not -path '*/node_modules/*'
find . -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.heic' \)

-iname is the case-insensitive version of -name. The second line excludes a folder you do not care about, which matters in code projects where dependency folders hold thousands of files. The third finds three photo extensions in one pass.

Both commands print full paths, one per line, so the results can be piped into other commands. Adding | wc -l gives a count, and | xargs passes the files to the next step. The one thing Terminal cannot do is show you the files the way Finder does, which is where the next section comes in.

Making extensions visible so you can trust what you see

Searching by extension is only half the job; reading the results is the other half. macOS hides most extensions by default, so a list of files called "report" may be a mix of .pdf, .docx and .pages files.

Apple's page on how to show or hide filename extensions gives two settings:

  • For all files: Finder > Settings > Advanced, tick "Show all filename extensions". This overrides every file's own setting.
  • For one file: select it, press Command-I, open Name & Extension and untick "Hide extension".

Turning on "Show all filename extensions" is worth doing before any extension search, so that the names in the results match the rules you typed. The same pane has "Show warning before changing an extension", which is worth leaving on: renaming .pdf to .txt does not convert anything, and the warning catches accidental changes.

In list view (Command-2), the Kind column is a second check. It shows the type macOS believes the file has, independent of the name. If a file's name ends in .pdf but its Kind says something else, the extension was changed by hand at some point.

When the search is the start of a task

Most extension searches are not the end goal. You find every .csv so you can merge them, every .heic so you can convert them, every .log so you can delete the old ones. Finder can find the files, and Terminal can act on them, but moving between the two means copying paths from one window and typing them into another.

That handoff is where people tend to look beyond Finder. A file manager with a built-in terminal keeps the folder and a shell in one window, so a search result and the command that acts on it share the same location. The list of features shows how that works, including saved searches and a terminal that follows the folder on screen. If you mainly want to know how this kind of tool differs from Finder and from other replacements, the comparison page sets them side by side. For most people, though, the Finder rule rows and one find command cover the job.

What to change first

Turn on "Show all filename extensions", build one Name ends with search and save it as a Smart Folder, and keep find -iname for the times when a missing file would matter. If the slow part turns out to be the step after the search, Atriens puts the folder and a terminal in the same window, and the Mac version is free.

Frequently asked questions

Why does Finder show files that do not have the extension I searched for?

Typing an extension into the search field without choosing a suggestion searches file contents as well as names, so documents that mention the extension in their text appear. Use a rule row set to Name and ends with, or choose the suggestion listed under Filenames, to match names only.

Can I search for several file extensions at once in Finder?

Yes. Click the plus button under the search field while holding Option, which adds a group. Set the group to Any, then add one Name ends with row for each extension. Saving the search turns it into a Smart Folder that keeps the combined list up to date.

Why does the find command return more files than Finder?

Finder and mdfind use the Spotlight index, while find reads the disk directly. Spotlight does not index the contents of app bundles and skips folders that have been excluded, and newly added files can take a moment to appear. find sees all of them, at the cost of speed.

Is searching by Kind the same as searching by extension?

Usually, but not always. Kind is based on the file's type as macOS records it, so a PDF with no extension is still found by kind:pdf, while a renamed file may show an extension that does not match its real type. Searching by Name ends with checks only the name.

Does Finder's extension search care about upper and lower case?

No. Finder's Name rules are not case sensitive, so .jpg also finds .JPG. In Terminal, use find -iname rather than -name, and add a trailing c to an mdfind name comparison, to get the same behaviour.

Back to all posts