Skip to content

mdfind MacOS Command Guide

The MacOS mdfind command allows users to search for files and metadata on their system using a variety of search criteria such as file name, content, file type, and more. This powerful command can help you quickly locate files and information across your system, making it easier to find what you need. By specifying search parameters, you can narrow down your search results and find the files you are looking for with ease. Additionally, mdfind supports advanced query options and syntax, allowing for complex and specific searches. With the mdfind command, you can search for files based on attributes like file creation date, modification date, file size, and more. This can be particularly useful when you need to find files that meet specific criteria or properties. In addition to searching for files, mdfind can also search for metadata associated with files, providing you with detailed information about the files on your system. Overall, mdfind is a versatile and powerful command that can help you effectively manage and organize your files on MacOS.

Terminal window
mdfind [option] [parameter]
OptionDescription
-onlyin pathSearch only within the specified path.
-name file_nameSearch for files with the specified name.
-liveContinuously update the search results.
-0Use null bytes to delimit results.
-sPerform a case-sensitive search.
-iPerform a case-insensitive search.
-literalTreat the query string as a literal string.
-interpretInterpret the query string.
-countDisplay the number of matching files.
-listDisplay the paths of matching files.
ParameterDescription
queryThe search query to be used.
Terminal window
mdfind -name pdf

This command will search for all PDF files on the system.

Section titled “Find files related to a specific application”
Terminal window
mdfind kMDItemContentType=com.apple.application-bundle

Searches for files related to a specific application by their content type.

Search for images modified within the last week

Section titled “Search for images modified within the last week”
Terminal window
mdfind "kMDItemLastUsedDate >= '\$time.now(-7h)' && kMDItemContentTypeTree == 'public.image'"

Finds images modified within the last week using a specific time range.

Locate files containing a specific keyword in the name

Section titled “Locate files containing a specific keyword in the name”
Terminal window
mdfind -name "keyword"

Searches for files containing a specific keyword in their name.

Terminal window
mdfind "kMDItemFSContentChangeDate >= '\$time.today(-1d)' && kMDItemContentTypeTree == 'public.text'"

Finds documents modified today based on the file system content change date.

Terminal window
mdfind "kMDItemFSSize > 10000 && kMDItemContentTypeTree == 'public.audio'"

Searches for audio files larger than 10MB on the system.

Terminal window
mdfind "kMDItemAuthors == 'Author Name'"

Finds files authored by a specific individual.

To use the mdfind command in MacOS, execute the following command:

Terminal window
mdfind --name "example.txt"

What are some common options used with mdfind in MacOS?

Section titled “What are some common options used with mdfind in MacOS?”

Common options used with the mdfind command in MacOS include:

Terminal window
mdfind -onlyin /path/to/directory "search query"

How can I search for specific file types with mdfind in MacOS?

Section titled “How can I search for specific file types with mdfind in MacOS?”

To search for specific file types using mdfind in MacOS, use the following command:

Terminal window
mdfind "kind:pdf"

Can I limit search results in mdfind to a specific location in MacOS?

Section titled “Can I limit search results in mdfind to a specific location in MacOS?”

Yes, you can limit search results in mdfind to a specific location by using the “-onlyin” option. Here’s an example:

Terminal window
mdfind -onlyin /path/to/directory "search query"

How can I search for files modified within a specific timeframe with mdfind in MacOS?

Section titled “How can I search for files modified within a specific timeframe with mdfind in MacOS?”

To search for files modified within a specific timeframe using mdfind in MacOS, you can utilize the “-onlyin” and “-newer” options. Here’s an example:

Terminal window
mdfind -onlyin /path/to/directory -newer "2021-01-01" "search query"

Is it possible to search for files based on their content with mdfind in MacOS?

Section titled “Is it possible to search for files based on their content with mdfind in MacOS?”

Yes, you can search for files based on their content using the mdfind command in MacOS. Here’s an example command:

Terminal window
mdfind "content:keyword"
  • Search for files or directories by name
  • Search for files by file content
  • Search for files by file type
  • Search for files by specific metadata attributes