RE: mdfind vs. find vs. ls ...
Hi all,
May I make one more suggestion?
The "find" and "ls" terminal commands work well, but I'd like to suggest the possible use of the "mdfind" command too. There are a couple of reasons, mostly for speed. In my hands, I find the "mdfind" commands to be faster for network shared drives. The reason is because searching the Spotlight indexing just appears to be significantly faster when searching a network drive from another machine. (Of course, the network drive must have Spotlight indexing turned on and the indexing must have already been performed before you can use "mdfind".)
For instance, when searching an iTunes Library with about 10000 songs on a network share (disk drive mounted on a Mac mini and shared via AFP) wirelessly from a rMBP, I found that the "find" command takes roughly 78 seconds while the "mdfind" command takes roughly 1 second.
In particular, the following two commands first change the directory to the shared network disk directory for the iTunes Library and then performs the "find" command to find the "Phantom of the Opera" songs. Since the "find" is running from the rMBP over the wireless network, this command executed in roughly 78 seconds:
Code:
cd /Volumes/Music/iTunes-Classical-AAC
find . -iname "*phantom*" -print
On the other hand, the following two commands first change the directory to the shared network disk directory for the iTunes Library and then performs the "mdfind" command to find the "Phantom of the Opera" songs. This command executed in roughly 1 second (too short for me to effectively time with my watch).
Code:
cd /Volumes/Music/iTunes-Classical-AAC
mdfind -onlyin . phantom
Both commands, run with the appropriate "sed" post-massaging, gave:
Code:
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 2]/2-07 Down Once More_Track Down This Murderer 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 2]/2-06 The Point of No Return 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 2]/2-05 Wandering Child_Bravo Monsieur 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 2]/2-04 Wishing You Were Somehow Here Again 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 2]/2-03 Notes_Twisted Every Way 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 2]/2-02 Masquerade_Why So Silent 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 2]/2-01 Entr'Acte 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 2]
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-14 All I Ask Of You 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-13 All I Ask Of You 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-12 Why Have You Brought Me Here..._Raoul, I've Been There... 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-11 Poor Fool, He Makes Me Laugh 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-10 Notes..._Prima Donna 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-09 Magical Lasso... 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-08 I Remember..._Stranger Than You Dreamt It... 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-07 Music Of The Night 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-06 Phantom Of The Opera 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-05 Little Lotte..._The Mirror... (Angel Of Music) 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-04 Angel Of Music 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-03 Think Of Me 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-02 Overture 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]/1-01 Prologue 1.m4a
Andrew Lloyd Webber/The Phantom Of The Opera [Disc 1]
So, to summarize, in my hands wirelessly searching an iTunes Library with about 10000 songs on a network disk took roughly 1 second using "mdfind" and roughly 78 seconds using "find".
... This is just another suggestion for searching large networked directory trees. The same "mdfind" will not only search iTunes Libraries but also iPhoto Libraries as well as any other directory trees.
Edit: And, of course, the "mdfind" command can search for other Spotlight indexing metadata also. See the "man mdfind" manpage for more information.
Regards,
Switon