Forrest logo
back to the mdfind tool

mdfind:tldr:1e68e

mdfind: Find a file by its name.
$ mdfind -name ${file}
try on your machine

The command "mdfind -name ${file}" is used in macOS to search for files by name using the Spotlight feature. Here is a breakdown of each component:

  • "mdfind": This is the command-line tool for interacting with the Spotlight search functionality on macOS. It allows you to perform complex searches across various attributes of files and metadata.

  • "-name": This is an option flag for the "mdfind" command that specifies the search criteria to be based on the file name.

  • "${file}": This is a placeholder for the actual file name you want to search for. By using the "${file}" syntax, you can substitute the variable with an actual file name when executing the command. For example, if you want to search for a file named "mydocument.txt", you would replace "${file}" with "mydocument.txt" resulting in "mdfind -name mydocument.txt".

To execute the command, you would open a terminal window on your Mac, type the command with the appropriate file name, and press enter. The "mdfind" tool would then perform the search and display the paths of any matching files.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the mdfind tool