Last week we discussed the locate command, and the week before, the find command. This week I will talk about mdfind: how to use it, and how it differs from the previous two commands.
mdfind indexes files on your OS that are used with Spotlight. It also searches user and system files by default and will even allow the user to search by file content and name. It is a bit more comprehensive than both the locate and find commands. The mdfind syntax is as follows:
mdfind name
I deal with a lot of invoices at work and often am searching for the correct one. mdfind helps out a lot in this regard. I need to find an invoice that was made for a local airport. I can’t remember the name but I do remember where it is located. First I navigated into my desktop folder, next I ran the command mdfind invoice. As you can see I have more results than I want.
I need to narrow down the search by providing a term. Since I am looking for an invoice related to airport, I will include that in the command. All words used in the search term are and’d together. Because of this I need to pass them as one argument and use double quotes. Now take a look at what it returns; the only invoice matching what I need.
The main purpose of these last three TT articles was just to show you how powerful Terminal can be, but I in no way have even scratched the surface. Please try and use these three commands to search for things you already know are there to get a hand of it, and then expand by using the “man find” command. Running “man” in front of any command will bring you to that specific commands manual page allowing you to see more in depth examples.