Even if you never use the unix locate command, OS X still runs in the background, updating the database for this command to quickly search your hard drive. It often turns out you don't want the unix locate command to search certain file systems or directories. The database it uses is updated by the locate.updatedbcommand that runs automatically as a cron job as part of your periodic maintainence. This hint is about how to tell locate.updatedb to avoid a filesystem, and it involves modestly editing a system file. My solution is to create a special Group-ID that tells updatedb not to index beyond a certain point; thus any folders or files below that initial folder with the special group ID are protected from being indexed.
MOTIVATION: I have a large 400GB FireWire drive on my computer that I use for backup images. It not only contains lots of files, but it also contains lots of hard linked files (created for differential backups). Running a find command on this filesystem can take hours. And since these are multiple backup copies of my principal directories, I dont want them in locate's database anyhow. Read on for the step-by-step solution...
- Create a plain text file called mypatch containing the following lines exactly:
42a43 > set EXCLUDE_GROUP = 399 # prune any path with a directory whose group is this name 63c64 < find ${SRCHPATHS} \( ! -fstype local -o -fstype fdesc -o -fstype devfs \) -a \ --- > find ${SRCHPATHS} \( ! -fstype local -o -fstype fdesc -o -fstype devfs -o -group ${EXCLUDE_GROUP} \) -a \
- Open a terminal window and type:
Note that the --backup flag will cause patch to create a copy of the original that you should keep in case you want to revert this. You can also use patch to revert with the -R flag).sudo patch --backup /usr/libexec/locate.updatedb mypatch
- [optional] Use Netinfo Manager to create a new Group. Call it whatever you wish, but give it a GID number of 399 as this is what the patch is expecting. I called mine noindx. The easiest way to do this reliably is to select and existing group, duplicate it, then edit the duplicate and save it.
- Now for any folder or file system you want locate.updatedb to avoid descending into, simply change its group ID to 399. The locate database will then not search any files or folders that are located underneath that path. Note you do not have to change the group-ID of all of the files you do not want indexed. You only need to change the group-ID of the top-level folder containing them.
CAVEAT: Editing system files is not something to undertake lightly. This is a fairly benign change, but don't do this if you are new to Unix. Keep the backup files (making your own is even a better idea). I had no choice, since update database ran for eight hours on my machine!