Adjust locate to include mounted HFS+ volumes

Feb 12, '03 10:00:44AM

Contributed by: Anonymous

I noticed that locate doesn't include mounted HFS+ volumes (those visible under /Volumes). Here's how to adjust that situation:

  1. Save the current shell script that updates the locate database:
     % sudo cp -p /usr/libexec/locate.updatedb \
    /usr/libexec/locate.updatedb.orig
  2. Update the shell script to include the mounted HFS+ volumes (use the name of your favorite editor in place of "edit", mine is bbedit):
     % sudo edit /usr/libexec/locate.updatedb
  3. Locate the find command (about 2/3 down towards the end of the file) and change -fstype devfs to -fstype devfs -o -fstype hfs (i.e., add the hfs filesystem type to the find command).

  4. Save the updated /usr/libexec/locate.updatedb

  5. Update the locate database (manually):
     % sudo /usr/libexec/locate.updatedb
The locate command (see: man locate) will now include the files from your locally mounted HFS+ volumes. If you want to revert back to the original locate DB update strategy, just type:
 % sudo cp -p /usr/libexec/locate.updatedb.orig \
/usr/libexec/locate.updatedb
Hope this helps.

[Editor's note: I broke the copy commands onto two lines using the backslash, so they should work if copied and pasted (they did when I tested), but if they don't, enter them as one line...]

Comments (0)


Mac OS X Hints
http://hints.macworld.com/article.php?story=200302120700449