Reindex Spotlight from the Command Line
Spotlight is generally very good at keeping a valid index of a drives contents up to date, but if you’ve recently restored a drive or had to delete the Spotlight index for one reason or another, you may need to reindex the drive manually. This is easy from the Spotlight control panel, and can also be achieved through the command line as we’ll demonstrate.
Reindexing Spotlight from the Command Line
Reindexing Spotlight from the command line is done with the mdutil tool, first launch Terminal and then type:
sudo mdutil -E /
This will reindex every mounted volume on the Mac, including hard drives, disk images, external drives, etc. Specific drives can be chosen by pointing to them in /Volumes/, to only rebuild the primary Macintosh HD:
sudo mdutil -E /Volumes/Macintosh\ HD/
To reindex an external drive named “External” the command would be:
sudo mdutil -E /Volumes/External/
Use of the mdutil command will spin up mds and mdworker processes as Spotlight goes to work.
Individually Reindexing Selected Files
In rare cases, Spotlight can miss a file during index, so rather than reindex an entire drive you can also manually add an individual file to the search index with the mdimport command:
mdimport /path/to/file
The mdimport command can be used on directories as well.





Mac OS X 10.7 Lion includes a great tool called tmutil that lets you interact with with Time Machine from the command line. It’s a powerful utility that has a ton of options and we’ve used it before to 






