Question

I recently moved my whole local web development area over to using MacPorts stuff, rather than using MAMP on my Mac. I've been getting into Python/Django and didn't really need MAMP any more.

Thing is, I have uninstalled MAMP from the Applications folder, with the preferences file too, but how come when I run the 'locate MAMP' command in the Terminal it still shows all my /Applications/MAMP/ stuff as if it's all still there? And when I 'cd' into /Applications/MAMP/ it doesn't exist?

Something to do with locate being a kind of index searching system, hence things these old filepaths are cached? Please explain why, and how to sort it so they don't show anymore.

Was it helpful?

Solution

You've got the right idea: locate uses a database called 'locatedb'. It's normally updated by system cron jobs (not sure which on OS X); you can force an update with the updatedb command. See http://linux-sxs.org/utilities/updatedb.html among others.


Also, if you don't find files which you expect to, note this important caveat from the BUGS section of OSX' locate(1) man-page:

The locate database is typically built by user ''nobody'' and the locate.updatedb(8) utility skips directories which are not readable for user ''nobody'', group ''nobody'', or world. For example, if your HOME directory is not world-readable, none of your files are in the database.

OTHER TIPS

The other answers are correct about needing to update the locate database. I've got this alias to update my locate DB:

alias update_locate='sudo /usr/libexec/locate.updatedb'

I actually don't use locate all that much anymore now that I've found mdfind. It uses the spotlight file index which OSX is much better at keeping up to date compared to the locatedb. It also has quite a bit more power in what it can search from the command line.

Indeed the locate command searches through an index, that's why it's pretty fast. The index is generated by the updatedb command, which is usually run as a nightly or weekly job.

So to update it manually, just run updatedb.

According to the man page, its database is updated once a week:

NAME
     locate.updatedb -- update locate database

SYNOPSIS
     /usr/libexec/locate.updatedb

DESCRIPTION
     The locate.updatedb utility updates the database used by locate(1).  It is typically run once a week by
     the /etc/periodic/weekly/310.locate script.

Take a look at the locate man page

http://unixhelp.ed.ac.uk/CGI/man-cgi?locate+1

You'll see that locate searches a database, not your actual filesystem. You can update that database by using the updatedb command.

Also, since it's a database, unless you do update it regularly, locate wouln't find files that are in your filesystem that arn't in the database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top