Command Line Spotlight

Spotlight is probably my favourite thing about Mac OS X. I recently found out that it’s possible to use spotlight on the command line using the mdfind command. But, the arguments I have to pass to it to get what I want mean that it’s a bit ‘wordy’ and not nearly as convenient to use as the Real Thing. So, I’ve written a tiny function that does exactly what I want:

function sl() {
  /usr/bin/mdfind -onlyin \. $@
}

If you put that in your .bash_profile you’ll have the…

sl

…command available to you (‘sl’ as in ‘SpotLight’). It allows you to type…

sl find this phrase

…which will search for files that contain ‘find this phrase’; but instead of searching system-wide, sl will search the current directory and all child directories.