How to stop 'locate' from using databases for unmounted volumes? Despite the claim made in the answer to this question:


Can Spotlight show results for disconnected drives?


This is exactly the behaviour I am seeing and I don't want it!

E.g.

wms:~ alan$ ls /Volumes
MobileBackups   Tamandua    
wms:~ alan$ locate /usr/texbin
/Volumes/AlanG5Backup/Previous Systems/Previous System 1/usr/texbin
/Volumes/AlanG5Backup/Previous Systems.localized/2009-07-10_1136/usr/texbin
/Volumes/MacBookBackup/usr/texbin


AlanG5Backup and MacBookBackup were partitions that I had previously mounted, but (as the output from ls /Volumes shows) were not mounted when I ran the locate command.

Furthermore, the current volume (Tamandua) doesn't show any locate results at all, which it should.

How do I fix this?  I'm running 10.9.
locate is not equivalent to Spotlight. 

Having said that, lets look at the meat of your question:

You can try to force an update of the locate db using sudo /usr/libexec/locate.updatedb which will rebuild the locates database.

I would check the manpage for locate for additional options regarding other volumes as I believe there is a flag to stay on the current filesystem from locate but it escapes me at the moment. Locate Man Page for 10.9

Having looked at it the best thing I can come up with is to use a regular expression that won't visit another filesystem or to create seperate databases for each.

Another option is to use the find command which can be told to stay on the current filesystem -x on BSD, -xdev in linux.