How do I find a file by filename in Mac OSX terminal?

I want to find a file on my Macbook with the filename: abc.dmg. I've tried to use spotlight, but it doesn't find it. When I tried find, and used: find -name abc.dmg -path /, I got errors back.

What is the proper syntax to find a file by filename with the find command on a Mac OSX terminal?


Solution 1:

In its simplest form, find takes one parameter: the path. In its actually useful form, it takes the path followed by narrowing criteria.

Thus, you want:

  • find (the program)
  • / (the path), and
  • -name abc.dmg (the criteria).
find / -name abc.dmg

Solution 2:

find . -name '*.csv' for instance worked for me with wildcards. OP could also use find . -name '*.dmg' to check his current directory, assuming he was in /.

Solution 3:

The mdfind command uses the Spotlight database

http://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/mdfind.1.html

Solution 4:

You can use the locate command.

locate abc.dmg