Mac spotlight and finder are great way to find files on Mac. But Mac also has command line utility mdfind (utility to query meta data) which can be used to find files on Mac. It uses the same meta data which is used by spotlight search but can also find system files. Here are some use cases.
Create sample test files for mdfind tutorial
- Create file1234.txt in /opt/tmp/dir1 with following content
file1234
- Create file4567.txt in /opt/tmp/dir2 with following content
file1234
mdfind – find files (file name or content) anywhere on Mac
$ mdfind file1234 /opt/tmp/tmp3/dir2/file5678.txt /opt/tmp/tmp3/dir1/file1234.txt
mdfind – find files (file name or content) in a dir
$ mdfind -onlyin dir1 file1234 /opt/tmp/tmp3/dir1/file1234.txt
mdfind – find files (file name only) anywhere on Mac
$ mdfind -name file1234 /opt/tmp/tmp3/dir1/file1234.txt