In OS X, you can use search for files in the command line using
mdfind to search for anything like you would in spotlight:
mdfind robocop will search for any file which contains the term robocop and return a list of paths. Just like spotlight, it will also search inside text documents, pdf documents, emails and so on.
-countto return the number of results instead of a list of files:
mdfind robocop -count
-liveto watch an live-update the list of results:
mdfind robocop -live
-onlyin <directory>to search in a specific path:
mdfind robocop -onlyin ~/Music
-name <name>to limit the search to filenames (won’t search inside files for example):
mdfind -name robocop
You can read a file’s metadata using the
Will print out a list of attributes and their values, something like:
_kMDItemOwnerUserID = 501
You can build more advanced queries and perform complex searches by using these metadata attributes using
Search for files whose type contains
mdfind "kMDItemKind == '*MPEG*'"
** Search for image files with a width > 3000 pixels**:
mdfind "kMDItemPixelWidth > 3000"
** Search for audio and movie files with a duration < 2 minutes**:
mdfind "kMDItemDurationSeconds < 120"