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.

mdfind Syntax:

Terminal window
mdfind [option] [parameter]

Options:

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.

Parameters:

ParameterDescription
queryThe search query to be used.

mdfind Command Samples:

Search for all PDF files

Terminal window
mdfind -name pdf

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

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

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

Terminal window
mdfind -name "keyword"

Searches for files containing a specific keyword in their name.

Search for documents modified today

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

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

Find all audio files larger than 10MB

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

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

Search for files by a specific author

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

Finds files authored by a specific individual.

mdfind FAQ:

How do I use mdfind in MacOS?

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?

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?

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?

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?

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?

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"

Applications of the mdfind command

  • 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