If you have ever used the locate command within Terminal to find a file of yours that, for instance, ends in .doc, you might find that you end up with more than 60,000 hits on your system that you didn't create, and didn't want to know about. Hence, it may be beneficial to create a user-level database for locate that searches only your local directory structure, so that you only see what belongs to you. To do this, and have my new database updated automatically, I modified a copy of the locate database update program that came with the Mac, set up a crontab to update this database hourly, and then created an alias for my local locate, called llocate. Now when I type llocate .doc , I only find 584 .doc files, and I can rest assured that they are all mine! Read on for the how-to...
Step 1: Copy and modify database update program I first copied the original program to a new directory, with this command:
cp /usr/libexec/locate.updatedb ~/bin/llocate.updatedb
I then modified the permissions on my copy:
chmod 755 ~/bin/llocate.updatedb
Finally, I made a few changes to the location of the new database directory, changed the pruned paths, and added vfat to my available filesystems, so that lines 52 to 54 now looked like this:
${FCODES:=$HOME/Library/llocate.database} # the database
${SEARCHPATHS:="$HOME"} # directories to be put in the database
${PRUNEPATHS:="$HOME/tmp $HOME/Library "} # unwanted directories
Step 2: set up crontab I created the file $HOME/bin/cron/crontab that contains the following line to get my llocate to update every hour at the 25 minute mark:
25 * * * * $HOME/bin/llocate.updatedb
Then I load the command into my crontab using crontab $HOME/bin/cron/crontab, and make sure it worked by typing crontab -l.
alias llocate='locate -d $HOME/Library/llocate.database'
You should now be able to easily "llocate" your own files!
Mac OS X Hints
http://hints.macworld.com/article.php?story=20080401141647236