#!/bin/bash # # Spotlight metadata find and grep by Daniel.Hoherd at gmail dot com ## Check for at least two arguments, print usage if else if [ $# -lt 1 ] ; then echo "usage: $0 searchstring [dir or file] [dir2 or file2]" exit ; fi ss=$1; shift; files=$@; until [ -z "$1" ] ; do thisitem=$1 onlyin="-onlyin '$thisitem' $onlyin" shift done; eval mdfind -0 $onlyin "$ss" | xargs -0 grep -Hi "$ss"
If you don't want to use this script, the same thing can be accomplished by hand by writing mdfind -0 -onlyin searchdir searchstring | xargs -0 grep -Hi searchstring. I've included the -H and -i options to more closely match the output of mdfind, but you can safely remove them.