Terminal Tips For Spotlight 0


Terminal Tips For Spotlight


While browsing the webs in the small moments of free time I actually have I came across a really interesting post about using Terminal tips for improving spotlight. You can find the post over at Mac Tips, I recommend you give it a good read. I wish I had thought of some of the tips on the site. While I am here I would like to point out one Terminal tip that you should find useful.

If you are building scripts, apps or pretty much anything with Terminal, you may want to to search your Spotlight database to find a specific file or folder. This is really easy to do. Simply type:


and then append at the end of the line the word or phrase you want to search for. If you have a multi word phrase make sure you surround it in double quotes or speech marks ( ” ” ).

The mdfind tool is a little broad, entering anything into the query section will bring back hundreds of results. You can easily cut it down. Simply add the following to restrict where it will look for files:

mdfind -onlyin ~/Documents

Again add a search word to the end of the phrase.

One cool little add on to this command is to add “-count” before the phrase you want to search for. This will not bring back any results but it will give you a number for the number of results. For instance if you search for “james” it will return a number of the number of documents containing the phrase “james”.

One of my favourite commands is the “-live” command which you can add to the string. This will give you a live update on the number of files and phrases. For every new file with your phrase it will add it to the list. For instance

mdfind -count -live -onlyin ~/Downloads "file name"

will give you a running total of the number of files the “file name” as the search query in the downloads folder. An interesting way of keeping track of files and folders in your downloads folder. You could combine something like this with Geektool to have interesting update on the number of files on your hard drive.

If you want to find out more information on how to use this Terminal tip check out the man page. If you have any interesting tips or tricks for this command, please leave a comment below.

If you want to keep up with the latests post from Mac Tricks And Tips I recommend you subscribe to the RSS Feed.

Where To Next?

  • Subscribe To Mac Tricks And Tips