Terminal 101: rebuild the Spotlight Index on the fly

(Image credit: Shutterstock)

Sometimes Spotlight doesn't behave properly, or perhaps doesn't know about files or folders that have just been created. 

Sometimes, it just forgets about files on external drives. When this happens, you can invoke a hidden feature (shown only through the Terminal commands) to cause your Spotlight Indexes to be rebuilt on either your Mac or any external drives connected to it. 

Let's walk through the process of how to do this.

Rebuild Spotlight on your Mac

If you're having issues finding files on your Mac, then you can easily rebuild the Spotlight index for your Mac by typing the following command into the Terminal app (located in /Applications/Utilities):

sudo mdutil -E /

After pressing enter, you'll be required to enter your password (because this command runs as a super user). 

After you do that, you will notice after a few minutes that when clicking the Spotlight button in the menu bar, Spotlight will show that it is currently indexing your system.

When Spotlight is indexing, it is building an extensive file that lets it quickly and easily search your system for just the item that you are looking for. 

This is why rebuilding the Spotlight index can fix a lot of issues stemming from wrong files showing in searches.

Rebuild Spotlight on any drive

Spotlight can build an index on each drive that is connected to the Mac for better searching on external drives. Fortunately, you can rebuild the Spotlight indexes on these drives as well. To do this, the the following command into the Terminal utility:

sudo mdutil -E /Volumes/[DriveName]

In the above command, you can either manually enter the drive name, or type in just the following portion of the command:

sudo mdutil -E

Then drag and drop a drive from the Finder on your Mac into the Terminal window. This will automatically enter the drive path and name for you. 

After pressing enter, you will once again be required to type in your account password. Again, Spotlight will begin building the index for the external drive within a few minutes of issuing this command.

TOPICS
Latest in Macs
A mockup of the possible Apple M3 Ultra logo
Performance isn't the only reason you should buy Apple's M3 Ultra Mac Studio - it's reportedly one of the most power-efficient processors too
Mac Studio on a desk
Apple Mac Studio (M3 Ultra): the ultimate creative workstation
Mac Studio from above.
New benchmark suggests Apple's M3 Ultra may not be much faster than the M4 Max - only a minor uplift in multi-core performance
Apple Mac Mini on wood desk
Forget President’s Day sales, Apple is selling an M2 Mac mini refurb for just over $300 which could be the PC bargain of the year
Sergii Figurnyi
Apple's M5 chip is rumored to be in mass production - but we're still waiting for M4 MacBook Airs
A hand holding up the new Mac mini M4
Apple's M4 Mac mini might be one of the best Macs ever, but it has a serious issue that needs fixing right now
Latest in How Tos
ChatGPT app on an iPhone
5 things you should ask ChatGPT today – oh, and 1 you should never ask it!
This City Is Ours
How to watch This City Is Ours online – stream Sean Bean crime drama from anywhere
Canada's Val Sweeting competes during the LGT World Womens Curling Championship match for third place ahead of Canada's showing at the Women's Curling World Championships 2025
Women's Curling World Championships live stream: how to watch Uijeongbu 2025 online, schedule, streaming guide
Thomas Tuchel, Head Coach of England, reacts during a training session at St George's Park on March 17, 2025 in Burton upon Trent, England.
England vs Albania live stream: How to watch 2026 World Cup qualifier online and from anywhere today, team news
Smartphone with new logo X twitter app background. Application twitter old blue bird change X black and white new.
How to delete all your tweets on X
ChatGPT Voice mode
How to add ChatGPT or Gemini voice mode to your iPhone Action button (while you wait for Siri's big upgrade)